How to import external type into global .d.ts file
When file has top-level import
or export
statement it is considered as a module. All its' content (types, interfaces, etc.) you are interested in needs to be exported explicitly in that file and imported in those files that need the types.
// types.d.ts
import { Thingy } from 'sick-lib';
export declare interface IInterface {
foo: any;
bar: any;
baz: Thingy;
}
// main.ts
import { IInterface } from 'types';
const xyz: IInterface = {
foo: true,
bar: false
};
Here's an example of a global.d.ts
file in a Create React App project:
declare type RouteProps = import("react-router-dom").RouteProps;
declare interface Xyz extends RouteProps {
yada: string;
}
With TypeScript 3.3+ (and maybe since the 2.4 because it's the version that added support for dynamic imports), you have better ways to solve this isssue, using either:
interface Test {
date: import('moment').Moment;
}
or
type Moment = import('moment').Moment;
interface Test {
date: Moment;
}
with no need to export any interfaces ;)