参考: https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html
0. 仅在 d.ts 文件中使用的,只需要 declare 声明一下
1. 将模块导出为全局变量,使用如下方法
````
/*~ If this module is a UMD module that exposes a global variable 'myLib' when
*~ loaded outside a module loader environment, declare that global here.
*~ Otherwise, delete this declaration. */
export as namespace myLib;
````
2. 导出函数
````
/*~ If this module has methods, declare them as functions like so. */
export function myMethod(a: string): string;
export function myOtherMethod(a: number): number;
````
3.导出变量
````
/*~ If the module also has properties, declare them here. For example,
*~ this declaration says that this code is legal:
*~ import f = require('myFuncLibrary');
*~ console.log(f.defaultName); */
export const defaultName: string;
export let defaultLength: number;
````
4.导出类
````
/*~ Write your module's methods and properties in this class */
export class MyClass {
constructor(someParam?: string);
someProperty: string[];
myMethod(opts: MyClass.MyClassMethodOptions): number;
}
````
5.使用 namespace点 访问的元素需要声明在 namespace 中
````
/*~ If you want to expose types from your module as well, you can
*~ place them in this block.
*~
*~ Note that if you decide to include this namespace, the module can be
*~ incorrectly imported as a namespace object, unless
*~ --esModuleInterop is turned on:
*~ import * as x from '[~THE MODULE~]'; // WRONG! DO NOT DO THIS! */
declare namespace MyClass {
export interface MyClassMethodOptions { width?: number; height?: number; }
}
````