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

Cannot use "interface" declarations from TypeScript in JS (React Native tests)

$
0
0

I have a ReactNative app and I am trying to write a test using Jest. My test need to use classes from a native component (react-native-nfc-manager) and a class I need is declared like this

  export interface TagEvent {    ndefMessage: NdefRecord[];    maxSize?: number;    type?: string;    techTypes?: string[];    id?: number[];  }

and if I try to use this definition directly like

const event = new TagEvent();

I get this error

TypeError: _reactNativeNfcManager.default is not a constructor

I am coming from Java worlds so I think to myself - of course it cannot instantiate an interface, it needs a class so I write a test instance for this interface:

class TestTagEvent implements TagEvent {    ndefMessage: NdefRecord[] = []    maxSize?: number;    type?: string;    techTypes?: string[];    id?: number[];}

But the problem seem to be different since it does not work either:

TypeError: _TestTagEvent.TestTagEvent is not a constructor

What am I missing?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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