tsconfigのlib
使用したいPolyfillを指定する
tsconfigのtargetで指定したtargetに使いたい機能が含まれていない、でも使いたい、という時にlibを指定する
tsconfigのtargetを指定すると、そのtargetで使われているlibraryは既に追加されている状態になる
docs
github
何を指定すればよいのか
tsconfig/basesでtarget、module、libを参考にする
libを別libraryで上書きする
TypeScript v4.5から楽にできるようになった
dependenciesに追記すれば、その名前の標準libを上書きできる
例えば、以下のように書けば、標準のdomではなく、@types/webが読み込まれる
code:tsconfig.json
{
lib: "dom"
}
code:package.json
{
"dependencies": {
"@typescript/lib-dom": "npm:@types/web"
}
}
libのversion管理もこの方法でできる
#WIP
以下の2通りのいずれかで指定する必要がある
と、ここに書いているが、公式には書いていないので本当なのかどうかわからん #??
一つも指定しない
code:tsconfig.json
{
"compilerOptions": {
"target": "es2018"
// "lib": []
}
}
2つ以上指定する
code:tsconfig.json
{
"compilerOptions": {
"target": "es2018",
"lib": [
"es2018",
"esnext.AsyncIterable",
"esnext.Array",
"esnext.Intl",
"esnext.Symbol"
]
}
}
targetと同じものをlibでも指定する必要があるらしい