https://www.typescriptlang.org/tsconfig#importsNotUsedAsValues
> [!warning]
> [[TypeScript 5.0]]では非推奨になったため[[verbatimModuleSyntax]]を使用すること。
`import`の挙動をコントロールする[[📒TSConfigのオプション]]。
| オプション | 値が使われていない`import`文を.. | default |
| ---------- | --------------------------------------- | ------- |
| `remove` | [[トランスパイル]]後のjsファイルから削除する | O |
| `preserve` | [[トランスパイル]]後のjsファイルに残す | |
| `error` | コンパイルエラーにする | |
以下のコードについて
```ts
import { Human } from "./someOtherModule";
import { Dog } from "./someOtherModule";
const taro = new Human(1, "tajo");
const pochi: Dog = {
id: 100,
name: "pochi",
};
```
それぞれのオプションで[[トランスパイル]]した結果は次の通り。
## remove
`Dog`は値が使われていないので削除される。
```js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const someOtherModule_1 = require("./someOtherModule");
const taro = new someOtherModule_1.Human(1, "tajo");
const pochi = {
id: 100,
name: "pochi",
};
//# sourceMappingURL=main.js.map
```
## preserve
`Dog`は値が使われていないので`require`文が残る。
```js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const someOtherModule_1 = require("./someOtherModule");
require("./someOtherModule");
const taro = new someOtherModule_1.Human(1, "tajo");
const pochi = {
id: 100,
name: "pochi",
};
//# sourceMappingURL=main.js.map
```
## error
`Dog`は値が使われていないのでコンパイルエラーになり[[トランスパイル]]できない。エラーメッセージは以下のとおり。`import type`を推奨される。
```
This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
```