33
27

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.

TypeScriptで型定義されていないモジュールを読み込む方法

Last updated at Posted at 2017-11-06

普通に

普通に読み込むとエラーになります。

app.ts
import * as hoge from 'hoge';

推奨

ソースフォルダに適当な名前.d.tsファイルを作って以下の内容を書きます。

types.d.ts
declare module 'hoge';

あとは普通に読みこめばOKです。

app.ts
import * as hoge from 'hoge';

ワイルドカード

ワイルドカードも使えます。

types.d.ts
declare module '*';

非推奨

これでも一応出来ますが、あまりおすすめはしません。

app.ts
declare function require(path: string): any;
const hoge = require('hoge');

参考

33
27
2

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
33
27

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?