1
次のTypeScript定義コードでは、Foo
インターフェイスのbaz
プロパティに関数タイプbaz
を再利用したいと思います。TypeScript:インターフェイス定義の関数定義を再利用
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
}
コピーペースト以外の定義を再利用する方法を見つけることができませんでした。コピー貼りよりも良い方法がありますか?インターフェイスを最初に定義し、メンバーを静的なエクスポートとして再利用する必要がある場合は、問題ありません。 baz
の
ありがとうございます! 'typeof'が答えでした。それは私の特定の質問に答えるのと同じようにすべきです: 'interface Foo = {(a:string):string; baz:typeof baz} 'と入力します。 – Avaq