class Foo { save(callback: (n: number) => any) : void { callback(42) } multipleCallbacks(firstCallback: (s: string) => void, secondCallback: (b: boolean) => boolean): void { firstCallback("hello world") let result: boolean = secondCallback(true) console.log("Resulting boolean: " + result) } } 使用 var foo = new Foo() foo.save((newNumber: number) => { console.log("Some number: " + newNumber) // This is optional, since "any" is the declared return type. return newNumber }) // Multiple callbacks example. // Each call is on a separate line for clarity. // Note that `firstCallback()` has a void return type, while the second is boolean. foo.multipleCallbacks( (s: string) => { console.log("Some string: " + s) }, (b: boolean) => { console.log("Some boolean: " + b) let result = b && false return result } )
查看更多关于TypeScript中是使用强类型函数作为参数的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did223448