Is there any way to reuse typings from one .d.ts
file inside another .d.ts file
to declare a module?
For example lets say we have the following vendor file:
node_modules/some-fancy-module/types.d.ts
export const valueA: number;
export const valueB: number;
Now in my project file I would like to declare that all *.special-file
imports will return valueA
and valueB
as shown on https://www.typescriptlang.org/docs/handbook/modules.html.
typings.d.ts
declare module '*.special-file' {
export * from 'some-fancy-module/types.d.ts';
}
unfortunately I can't manage to use those typings:
import {valueA} from './my.special-file';
Error: Module '"*.special-file"' has no exported member 'valueA'
Screenshot:
CodeSandbox as seen on the screenshot: https://codesandbox.io/s/reexport-types-5h8hb?file=/src/index.ts
You can import and then export within the declaration. The following works:
declare module '*.foo' {
import {valueA} from './third-party/types.d.ts';
export = valueA
}
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