Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6211

React-native: Exporting a user defined type as default causes "can't find variable" error

$
0
0

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:

  1. "tslint": "5.17.0"
  2. "tslint-react": "4.0.0"
  3. "type-zoo": "3.4.1"
  4. "typescript": "3.7.5"
  5. "@babel/core": "7.4.5"
  6. "@babel/runtime": "7.4.5"

React project:

  1. "type-zoo": "3.4.1",
  2. "typescript": "3.7.5"

Viewing all articles
Browse latest Browse all 6211

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>