問題
TypeScript (2.0.10) において次のように利用するための foo.d.ts
の書きかたが分からない。
import * as f from 'foo';
const n: number = 123;
const s: string = f(n);
console.log(s);
解決策
foo.d.ts
declare module 'foo' {
namespace foo {} // この行がポイント
function foo(n: number): string;
export = foo;
}
-
namespace foo {}
をなしにするとexport = foo;
が通らない。 -
export default foo;
とするとimport * as f from 'foo';
が通らない。