型がわからない関数について、特定の呼び出しシグネチャを持つことを確認することはできますか?
下記の例で言うと mod.execute
は (a: string, b: number) => [boolean, string]
という型を持つことを確認して、もし違ったならエラーを発生させたいのですが。
typescript
1const mod = await import('/home/foo/mod.ts') // 動的インポート(foo/mod.ts には execute() という関数が定義され export されている) 2if ('execute' in mod && typeof mod.execute === 'function'){ 3 const execute: (a: string, b: number) => [boolean, string] = mod.execute 4 let [doFinish, str]: [boolean, string] = execute('string', 1) 5}
あなたの回答
tips
プレビュー