I
I
IDONTSUDO2020-05-16 14:20:18
typescript
IDONTSUDO, 2020-05-16 14:20:18

TypeScript interfaces accessed from global space?

I have this line in my config.

"types": ["react","node","ragemp-c"]

, I installed these interfaces via NPM package. And they are available in the global space, I can not import them in order to initialize. How can I do the same with my working interfaces?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2020-05-16
@bingo347

You can specify in the types field any package installed in node_modules or in node_modules/@types that has the types field in package.json
. You can also simply drop a file with any name with a .d.ts extension to the root of the project (where tsconfig.json ), but with such a name that the .js file of the same name does not lie next to it, for example global.d.ts if global.js is missing.
Any declarations in such a file will be global.
You can also declare modules for import in it, for example for css-modules:

declare module '*.css' {
  const classes: Readonly<Record<string, string>>;
  export default classes;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question