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

Importing javascript function into Typescript file: function is seen as namespace

$
0
0

I'm trying to import a plain javascript function into a typescript file. I'm working on a React Native app.

The import is working when its just JS, but on TS I get the error: Cannot use namespace 'PrimaryButton' as a type

The javascript function resides in a node module which exports its function as such in its index.js:

export {default as PrimaryButton} from './src/components/PrimaryButton.js';

The node module is called component-library, it is a company own node module. It does not contain any types at all, only plain JS.

I have included a custom.d.ts file in the RN app where I declare component-library as a module to avoid TS errors on import:

declare module 'component-library';

Now, when trying to import the PrimaryButton function, I get the error Cannot use namespace 'PrimaryButton' as a type.

What is the easiest way to enable to import of the PrimaryButton function without errors? I'm pretty new to Typescript and kind of lost here.


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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