2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

`import * as f from 'foo';` のための `foo.d.ts` の書きかた

Posted at

問題

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'; が通らない。
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?