Reputation: 91
Let's assume that we have type provided by some file like types.d.ts
declare function test(arg: string): void;
Is there a way to import types into own type definition and wrapped it into namespace? i would like to have something like
import { test } from 'some-weird-module/types.d.ts';
declare namespace MyModule {
export test;
}
Upvotes: 0
Views: 595
Reputation: 91
My requirements was completely resolved by new TypeScript 3.8 version, they introduced type only imports https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#-type-only-imports-and-export
Upvotes: 1
Reputation: 3061
Types in a .d.ts
file should not need to be imported => skip import { test } from 'some-weird-module/types.d.ts';
.
Then, I don't thing that it's possible to wrap these types in a namespace in one line. But, for each type to export, we can try to create a type alias that can be exported:
declare namespace MyModule {
export type T1bis = T1; // T1 came from 'some-weird-module/types.d.ts'
export type T2bis = T2; // T2 came from 'some-weird-module/types.d.ts'
// etc.
}
Upvotes: 0