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';
export {default as PrimaryButton} from './src/components/PrimaryButton.js';
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.