Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reexport all typings inside a typescript .d.ts definition file

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 screenshot of the issue

CodeSandbox as seen on the screenshot: https://codesandbox.io/s/reexport-types-5h8hb?file=/src/index.ts

like image 402
jantimon Avatar asked Jun 24 '20 10:06

jantimon


1 Answers

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
}
like image 187
K4M Avatar answered Oct 08 '22 16:10

K4M