I have a typescript project using node.js. There is a module i want to use npm package country-code-lookup.
The problem is it does not have a supporting types declaration for it. However, i'd still like to use it.
Is it possible i could still use this package without the typings.
import * as CountryCodeLookup from "country-code-lookup";
const countryCodes = CountryCodeLookup.countries;
console.log(countryCodes);
I get the following error when typescript attempts to compile.
TS7016: Could not find a declaration file for module 'country-code-lookup'. '/Users/kay/portal/node_modules/country-code-lookup/index.js' implicitly has an 'any' type. Try
npm install @types/country-code-lookup
if it exists or add a new declaration (.d.ts) file containingdeclare module 'country-code-lookup';
When you have this error, it is usually because you installed a library and you didn't install the types of that library. To fix this error, you need to install @types/library-name using your package manager (npm or yarn).
The TypeScript declares module is one of the modules and keyword it is used for to surround and define the classes, interfaces; variables are also declared it will not originate with the TypeScript like that module is the set of files that contains values, classes, functions/methods, keywords, enum all these contains ...
If you have no problems simply ignoring all type-checking features for this library, you have two options:
// @ts-ignore
above all imports, like so:// @ts-ignore
import * as CountryCodeLookup from "country-code-lookup";
any
type, so all imports are automatically considered to be of any
type.To do so, create a file src/types/country-code-lookup/index.d.ts
Add the following declaration:
// country-code-lookup/index.d.ts
declare module 'country-code-lookup';
In this file, later you can add your own type definitions. If they are good enough, push them do DefinitelyTyped, so all the community can use and improve it!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With