I'm using React and React-native for my web application and mobile projects. both projects are written in typescript.
In the React web application, I have defined a type C
and exported it as default;
myTypes.ts
export interface A {
// a few attributes
}
export interface B {
// a few attributes
}
type C = A | B;
export default C;
so I can simply import C
using import C from 'PATH/TO/myTypes';
I using the same file in my React-Native project but when I run the application I got can't find variable: C
error message.
The error is gone when I made these changes
+export type C = A | B; // export C at this line
-export default C; // and removing this line
and import C
using import { C } from 'PATH/TO/myTypes';
I'm wondering why I can't export a user-defined type as default in React-Native.
It worths to mention that I'm using the same typescript version for both projects. other information about typescript related dependencies is listed below.
React-Native project:
- "tslint": "5.17.0"
- "tslint-react": "4.0.0"
- "type-zoo": "3.4.1"
- "typescript": "3.7.5"
- "@babel/core": "7.4.5"
- "@babel/runtime": "7.4.5"
React project:
- "type-zoo": "3.4.1",
- "typescript": "3.7.5"