I'm developing react application using typescript.
Here is my App.tsx. As you can see react has @types but other modules don't
Is there any way to stub these modules or use them as any or another
3 Answers 3
All the modules you're referring have @types. But let's assume that the module you're using doesn't, e.g. the library kea(keajs) doesn't have @type defined to this date.
The simplest way to solve this is to create a declaration file declarations.d.ts and declare the problematic module like this:
declare module "kea"
Then in your tsconfig.json you need to be sure that in include property you have something like:
...
"include": [
"src", "declarations.d.ts"
]
...
Or just put declarations.d.ts inside your src folder so you don't need to touch this file.
Be wary that you won’t have any types for the module (the module will be just a big any); but you won’t have any errors.
Comments
If anyone still wondering what to do in case of missing @types/module type definitions, dts-gen can cover the missing type and generate a .d.ts for that specific module.
Comments
Actually, I am pretty sure these modules have @types. Check here:
https://www.npmjs.com/package/@types/react-redux https://www.npmjs.com/package/@types/redux-persist https://www.npmjs.com/package/@types/react-router
If you use NPM, you can install, react-redux for instance, doing:
npm install --save-dev @types/react-redux
7 Comments
.d.ts file containing some declarations. These declarations can be as easy as any or as complex as you need.any' declarations manually for each package? It looks uncomfortably if i just need a stub for package
@typesover here: microsoft.github.io/TypeSearch