I am currently converting a JavaScript application to TypeScript. I am using an NPM module, which has incomplete typings. Specifically I am using AWML.
Most things worked well, but now I want to use a function, which is not defined in the typings of the module. If I just use
import { registerBackendType } from "@deutschesoft/awml/src/components/backend";
I get the message
Could not find a declaration file for module ‘@deutschesoft/awml/src/components/backend’. ‘C:/…/node_modules/@deutschesoft/awml/src/components/backend.js’ implicitly has an ‘any’ type.
As I have set "noImplicitAny": false
, this still works, but I get no typing support, which kind of defeats the purpose of using TypeScript. To fix this, I tried to implement my own declaration file like this in a file called types/backend.d.ts
:
declare module '@deutschesoft/awml/src/components/backend.js' {
import { BackendBase, IBackendBaseOptions } from "@deutschesoft/awml/src/backends/backend_base";
export function registerBackendType<B extends BackendBase, O extends IBackendBaseOptions>(type: string, constructor: { new(options: O): B }): void;
}
This does not fix the problem, the message is still the same. Adding /// <reference path="../types/backend.d.ts" />
above the import, as this answer suggests, also does nothing.
Importing the function directly from the declaration file results in a different error:
File ‘C:/…/types/backend.d.ts’ is not a module.
The best answer that I have found for this suggests placing import
and export
statements inside the declaration, which I already did. I also tried a lot of different export and import syntax variations, none have solved the problem.
How can I add a declaration, so that I get full typing support for this function?