【发布时间】:2018-01-10 19:36:14
【问题描述】:
在下面的 TypeScript 定义代码中,我想为Foo 接口的baz 属性重用baz 的函数类型。
declare module 'foo' {
/* Not all exports will be reused in the interface. */
export function bar(a: string): string
/* Imagine a big and verbose function
definition with plenty overloadings: */
export function baz(a: number): number
export function baz(a: Overloaded): number
interface Foo {
/* The interface is for a function, so I cannot use module */
(a: string): string
/* how do I reuse the full definition of the baz function? */
baz
}
export default Foo
}
除了复制粘贴之外,我还没有找到重用定义的方法。有没有比复制粘贴更好的方法?如果我必须先定义接口并将其成员重用为静态导出,那也没关系。
【问题讨论】: