A
A
Alexey Nikolaev2019-11-06 20:16:21
typescript
Alexey Nikolaev, 2019-11-06 20:16:21

How to make Typescript load declaration files automatically?

Good evening.
There is the following situation: several plug-ins (services) inside one application, for which there are several well-structured declaration files. Services are imported with relative paths. For example, there is a file "oauthHandlers.js" which uses types from "OauthPlugin.d.ts".
Problem: tsc doesn't load OauthPlugin.d.ts automatically. You have to constantly do imports in oauthHandlers.js in order for the types to work. I know that TS matches the required declarations in the paths before them, and the easiest way is to name the file oauthHandlers.d.ts and put it in the same directory as oauthHandlers.js, but in my case this cannot be done.
How to make OauthPlugin.d.ts loaded for any type calls in it? Now I use the following crutch in global.d.ts:

import { SomePlugin } from 'plugins';
// Будет доступен глобально во всей системе
declare type SomePlugin = SomePlugin;

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question