1.参数固定属性,且函数返回值必须是number类型 |
let isAdd : (x : number , y : number) => number;
2.参数固定属性,且函数返回值必须是number类型,跟上面是等价的 |
interface Add {
(x:number , y:number) : number
}
type Add = (x: number , y: number) => number;
let isadd : Add = (x:number , y:number) => {return x + y};
interface Lib {
():void,
version : string,
doSomething():void
}
let lib : Lib = (() => {}) as Lib;
lib.version = "1.0";
lib.doSomething = () => {};
function getLib(){
let lib : Lib = (() => {}) as Lib;
lib.version = "1.0";
lib.doSomething = () => {};
return lib;
}
let lib1 = getLib();
lib1.doSomething();
let lib2 = getLib();
lib2.doSomething();