Typescript的d.ts⽂件规范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 {
export declarationconstructor(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; } }
````

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。