TypeScript を 6 から 7 に上げると動かなくなること
TypeScript を 6 から 7 に上げると、ignoreDeprecations で黙らせていた baseUrl などが TS5102・TS5108 で止まり、ts-node と typescript-eslint も動かなくなる。
6 と 7 で打ち比べた 8 つの変更点と直し方をまとめる。
公開: 更新:
typescript@6 を入れたプロジェクトと、同じファイルのまま typescript@7 に上げたプロジェクトを並べ、同じコマンドを打ち比べた。
各節の出力は「v6 では」「v7 に上げると」「v7 で直すと」の 3 段で並ぶ。
7.0 は Go で書き直したコンパイラである。
公式のアナウンスによると、stableTypeOrdering を有効にし、ignoreDeprecations を付けずに 6.0 でエラーなく通るコードは、ほぼすべて 7.0 でも同じ結果になる。
動かなくなる原因は大きく 3 つある。
1 つは、6.0 が非推奨にした設定が 7.0 でエラーになったことである。
6.0 では "ignoreDeprecations": "6.0" を書けばエラーを黙らせられたが、7.0 ではこの指定が効かない。
2 つ目は、require("typescript") で呼べる JavaScript の API が 7.0 に無いことで、ts-node や typescript-eslint のように API を使う道具が動かなくなる。
3 つ目は、JavaScript のファイルを JSDoc で検査するときの扱いが変わったことである。
tsconfig の 4 つの変更点は、6.0 を ignoreDeprecations なしで走らせると、TS5101 か TS5107 のエラーとして先に出る。
このページで見せたのは baseUrl の TS5101 だけで、4 つとも 6.0 で出るところは TypeScript を 5 から 6 に上げると動かなくなること で打っている。
どちらの番号も「7.0 で動かなくなる」という予告で、7.0 ではそれぞれ TS5102 と TS5108 に変わった。
上げる前に tsconfig から ignoreDeprecations を消して npx tsc -p . を打てば、7.0 で止まる設定がまとめて分かる。
公式のアナウンスが 7.0 でエラーにするとした次の設定は、このページでは打っていない。
moduleのamd・umd・systemjs・noneと、"moduleResolution": "classic"は使えない。allowSyntheticDefaultImportsとalwaysStrictはfalseにできない。module Utils {}の形の namespace の宣言と、importに付けるassertsはエラーになる。skipDefaultLibCheckのとき、/// <reference no-default-lib />は効かない。
同じアナウンスは、Vue・MDX・Astro・Svelte などを使うプロジェクトはまだ 7.0 を使えない見込みだと書いている。
Angular のテンプレートの型検査も、7.0 を使わない見込みである。
baseUrl が使えなくなった
baseUrl は、import のパスを解決する起点を決める設定である。
6.0 で非推奨になり、7.0 で消えた。paths の別名(@/* など)と組み合わせて書いているプロジェクトが多い。
v6 では
$ cat tsconfig.json
{
"compilerOptions": {
"noEmit": true,
"baseUrl": ".",
"paths": { "@/*": ["src/*"] }
},
"include": ["src"]
}$ npx tsc -p .
tsconfig.json(4,5): error TS5101: Option 'baseUrl' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
Visit https://aka.ms/ts6 for migration information.
$ echo $?
2$ cat tsconfig.json
{
"compilerOptions": {
"noEmit": true,
"baseUrl": ".",
"paths": { "@/*": ["src/*"] },
"ignoreDeprecations": "6.0"
},
"include": ["src"]
}$ npx tsc -p .
$ echo $?
0v7 に上げると
$ npx tsc -p .
tsconfig.json(4,5): error TS5102: Option 'baseUrl' has been removed. Please remove it from your configuration.
Use '"paths": {"*": ["./*"]}' instead.
tsconfig.json(5,24): error TS5090: Non-relative paths are not allowed. Did you forget a leading './'?
$ echo $?
1v7 で直すと
$ cat tsconfig.json
{
"compilerOptions": {
"noEmit": true,
"paths": { "@/*": ["./src/*"] }
},
"include": ["src"]
}$ npx tsc -p .
$ echo $?
0$ cat src/index.ts
import { add } from "lib/math";
console.log(add(1, 2));$ cat tsconfig.json
{
"compilerOptions": {
"noEmit": true,
"baseUrl": "./src"
},
"include": ["src"]
}$ npx tsc -p .
tsconfig.json(4,5): error TS5102: Option 'baseUrl' has been removed. Please remove it from your configuration.
Use '"paths": {"*": ["./src/*"]}' instead.
$ echo $?
1$ cat tsconfig.json
{
"compilerOptions": {
"noEmit": true
},
"include": ["src"]
}$ npx tsc -p .
src/index.ts(1,21): error TS2307: Cannot find module 'lib/math' or its corresponding type declarations.
$ echo $?
1$ cat tsconfig.json
{
"compilerOptions": {
"noEmit": true,
"paths": { "*": ["./src/*"] }
},
"include": ["src"]
}$ npx tsc -p .
$ echo $?
07.0 は TS5102 と一緒に、paths の src/* にも TS5090 を出した。baseUrl が無いと、paths の行き先は ./ で始まる相対パスでなければならない。baseUrl を消し、行き先を tsconfig.json からの相対パス(./src/*)に書き直すと、どちらのエラーも消える。
"baseUrl": "./src" を書き、"lib/math" のように paths を通さない名前で import していたプロジェクトでは、TS5102 が Use '"paths": {"*": ["./src/*"]}' instead. と受け皿の書き方を示した。baseUrl を消すだけでは TS2307 になり、この受け皿を paths に足すと通る。
TSConfig リファレンスによると、paths は型の検査のための設定で、出力した JavaScript の import は書き換えない。
ここでは noEmit で検査だけをしたので、出力を Node.js で動かすところは打っていない。
moduleResolution: node が使えなくなった
"moduleResolution": "node" は Node.js 10 の頃の解決方法で、7.0 では node10 という名前でエラーになる。"classic" も同じく使えない。
v6 では
$ cat tsconfig.json
{
"compilerOptions": {
"noEmit": true,
"module": "commonjs",
"moduleResolution": "node",
"ignoreDeprecations": "6.0"
},
"include": ["src"]
}$ npx tsc -p .
$ echo $?
0v7 に上げると
$ npx tsc -p .
tsconfig.json(5,25): error TS5108: Option 'moduleResolution=node10' has been removed. Please remove it from your configuration.
$ echo $?
1v7 で直すと
$ cat tsconfig.json
{
"compilerOptions": {
"noEmit": true,
"module": "commonjs",
"moduleResolution": "bundler"
},
"include": ["src"]
}$ npx tsc -p .
$ echo $?
0$ cat tsconfig.json
{
"compilerOptions": {
"noEmit": true,
"module": "nodenext"
},
"include": ["src"]
}$ npx tsc -p .
$ echo $?
0$ npm pkg get type
"commonjs"$ npm pkg set type=module
$ echo $?
0$ npx tsc -p .
src/index.ts(1,21): error TS2835: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './lib/math.js'?
$ echo $?
1$ cat src/index.ts
import { add } from "./lib/math.js";
console.log(add(1, 2));$ npx tsc -p .
$ echo $?
0Vite や webpack のようなバンドラーでまとめるプロジェクトは "moduleResolution": "bundler" にする。
拡張子を省いた import も今までどおり通った。
Node.js で直接動かすプロジェクトは "module": "nodenext" にする。
このとき moduleResolution も nodenext になることは、TS2835 の文言に出ている。
拡張子を省いた ./lib/math がそのまま通ったのは、package.json が npm 11 の npm init -y の書いた "type": "commonjs" だったからである。"type": "module" に変えると TS2835 になり、import に .js を付けると通る。
target: es5 と downlevelIteration が使えなくなった
7.0 が出力できる一番古い JavaScript は ES2015 になった。
ES5 向けの出力で for...of などを書き直すための downlevelIteration も消えた。
v6 では
$ cat tsconfig.json
{
"compilerOptions": {
"noEmit": true,
"target": "es5",
"lib": ["es2015", "dom"],
"downlevelIteration": true,
"ignoreDeprecations": "6.0"
},
"include": ["src"]
}$ npx tsc -p .
$ echo $?
0v7 に上げると
$ npx tsc -p .
tsconfig.json(4,15): error TS5108: Option 'target=ES5' has been removed. Please remove it from your configuration.
tsconfig.json(6,5): error TS5102: Option 'downlevelIteration' has been removed. Please remove it from your configuration.
$ echo $?
1v7 で直すと
$ cat tsconfig.json
{
"compilerOptions": {
"noEmit": true,
"target": "es2015"
},
"include": ["src"]
}$ npx tsc -p .
$ echo $?
0target を es2015 以上にし、downlevelIteration を消す。
公式のアナウンスによると、target を書かなければ、esnext の 1 つ前の安定した ECMAScript の版が既定になる(打っていない)。
古いブラウザのために ES5 のコードが要るなら、TypeScript の出力を Babel や SWC で ES5 に変換する。
esModuleInterop: false が書けなくなった
esModuleInterop は、CommonJS のパッケージを import で読むときの変換を ECMAScript の仕様に近づける設定である。
7.0 では常に有効で、false を書くとエラーになる。
設定を消すだけでは終わらないことがあり、import * as で読んだ関数を呼んでいたコードは型エラーになる。
ここでは Express のミドルウェアの cors を使った。
v6 では
$ cat src/index.ts
import * as cors from "cors";
const middleware = cors({ origin: "https://dekinai.dev" });
console.log(typeof middleware);$ cat tsconfig.json
{
"compilerOptions": {
"noEmit": true,
"module": "commonjs",
"esModuleInterop": false,
"ignoreDeprecations": "6.0"
},
"include": ["src"]
}$ npx tsc -p .
$ echo $?
0v7 に上げると
$ npx tsc -p .
tsconfig.json(5,24): error TS5108: Option 'esModuleInterop=false' has been removed. Please remove it from your configuration.
$ echo $?
1$ cat tsconfig.json
{
"compilerOptions": {
"noEmit": true,
"module": "commonjs"
},
"include": ["src"]
}$ npx tsc -p .
src/index.ts(3,20): error TS2349: This expression is not callable.
Type '{ default: <T extends e.CorsRequest = CorsRequest>(options?: CorsOptions | CorsOptionsDelegate<T> | undefined) => (req: T, res: { statusCode?: number | undefined; setHeader(key: string, value: string): any; end(): any; }, next: (err?: any) => any) => void; }' has no call signatures.
$ echo $?
1v7 で直すと
$ cat src/index.ts
import cors from "cors";
const middleware = cors({ origin: "https://dekinai.dev" });
console.log(typeof middleware);$ npx tsc -p .
$ echo $?
0module.exports に関数を入れているパッケージは、import cors from "cors" のように既定の import で読む。import * as で読んだものは名前空間のオブジェクトなので、esModuleInterop が有効だと呼び出せない。@types/cors のように、型定義が関数と namespace を合わせて export = で出しているパッケージで起きる。
ts-node が TypeError で落ちるようになった
7.0 の typescript パッケージには createProgram などの JavaScript の API が無い。require("typescript") で読めるのは版の番号だけになった。
API を使って .ts を変換する ts-node は、起動したところで TypeError になる。
v6 では
$ cat hello.ts
const site: string = "dekinai";
console.log(`hello, ${site}`);$ npx ts-node hello.ts
hello, dekinai
$ echo $?
0$ node -e 'const ts = require("typescript"); console.log(ts.version, typeof ts.createProgram)'
6.0.3 functionv7 に上げると
$ npx ts-node hello.ts
/work/v7/node_modules/ts-node/dist/configuration.js:91
const { fileExists = ts.sys.fileExists, readFile = ts.sys.readFile, skipProject = index_1.DEFAULTS.skipProject, project = index_1.DEFAULTS.project, tsTrace = index_1.DEFAULTS.tsTrace, } = rawApiOptions;
^
TypeError: Cannot read properties of undefined (reading 'fileExists')
at readConfig (/work/v7/node_modules/ts-node/dist/configuration.js:91:33)
at findAndReadConfig (/work/v7/node_modules/ts-node/dist/configuration.js:50:84)
at phase3 (/work/v7/node_modules/ts-node/dist/bin.js:254:67)
at bootstrap (/work/v7/node_modules/ts-node/dist/bin.js:47:30)
at main (/work/v7/node_modules/ts-node/dist/bin.js:33:12)
at Object.<anonymous> (/work/v7/node_modules/ts-node/dist/bin.js:579:5)
at Module._compile (node:internal/modules/cjs/loader:1929:14)
at Object..js (node:internal/modules/cjs/loader:2060:10)
at Module.load (node:internal/modules/cjs/loader:1651:32)
at Module._load (node:internal/modules/cjs/loader:1443:12)
Node.js v24.22.2
$ echo $?
1$ node -e 'const ts = require("typescript"); console.log(ts.version, typeof ts.createProgram)'
7.0.2 undefinedv7 で直すと
$ node hello.ts
hello, dekinai
$ echo $?
0$ cat typo.ts
const count: number = "three";
console.log(count);$ node typo.ts
three
$ echo $?
0$ npx tsc -p . --noEmit
typo.ts(1,7): error TS2322: Type 'string' is not assignable to type 'number'.
$ echo $?
1$ npm install -D "typescript@npm:@typescript/typescript6@^6.0.2" "@typescript/native@npm:typescript@^7.0.2" ts-node@10 @types/node@24
added 23 packages in 1s
$ echo $?
0$ npx tsc -v
Version 7.0.2$ npx tsc6 -v
Version 6.0.3$ npx ts-node hello.ts
hello, dekinai
$ echo $?
0型の検査が要らず、手元のスクリプトを動かすだけなら、hello.ts のように型の注釈を足しただけのファイルは Node.js 24 がそのまま実行した。
Node.js は型を検査しないので、number の変数に文字列を入れた typo.ts も動き、tsc --noEmit で初めて TS2322 が出た。enum のように注釈を取り除くだけでは動かない書き方や、拡張子を省いた import を含むファイルは打っていない。
ts-node を使い続けるなら、npm のエイリアスで 6.0 と 7.0 を同じプロジェクトに入れる。typescript という名前に @typescript/typescript6(6.0 の API とコマンド tsc6)を割り当て、7.0 は @typescript/native という別名で入れる。require("typescript") は 6.0 を読み、npx tsc は 7.0 を動かす。
typescript-eslint が npm install できなくなった
typescript-eslint は TypeScript の API でコードを読むので、peerDependencies が 7.0 を含んでいない。typescript@7 のプロジェクトに入れようとすると、npm が依存関係を解決できずに止まる。
npm が勧める --legacy-peer-deps を付ければ入るが、ESLint を動かすと typescript-eslint 自身が 7.0 には対応していないと言って止まる。
v6 では
$ npm install -D eslint typescript-eslint
added 93 packages in 4s
$ echo $?
0$ npx eslint src
$ echo $?
0v7 に上げると
$ npm install -D eslint typescript-eslint
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: v7@1.0.0
npm error Found: typescript@7.0.2
npm error node_modules/typescript
npm error dev typescript@"^7.0.2" from the root project
npm error
npm error Could not resolve dependency:
npm error peer typescript@">=4.8.4 <6.1.0" from typescript-eslint@8.72.1
npm error node_modules/typescript-eslint
npm error dev typescript-eslint@"*" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry this command with --force or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error /root/.npm/_logs/2026-11-08T03_37_04_617Z-eresolve-report.txt
npm error A complete log of this run can be found in: /root/.npm/_logs/2026-11-08T03_37_04_617Z-debug-0.log
$ echo $?
1$ npm install -D --legacy-peer-deps eslint typescript-eslint
added 93 packages in 2s
$ echo $?
0$ npx eslint src
typescript-eslint does not support TS 7.0.
Please see https://devblogs.microsoft.com/typescript/announcing-typescript-7-0/#running-side-by-side-with-typescript-6.0 to run typescript-eslint using the TS 6 API.
See also https://github.com/typescript-eslint/typescript-eslint/issues/10940 for tracking typescript-eslint's support for TS >=7.1
Oops! Something went wrong! :(
ESLint: 10.14.0
Error: typescript-eslint does not support TS 7.0.
at Object.<anonymous> (/work/v7/node_modules/typescript-eslint/dist/index.js:52:11)
at Module._compile (node:internal/modules/cjs/loader:1929:14)
at Object..js (node:internal/modules/cjs/loader:2060:10)
at Module.load (node:internal/modules/cjs/loader:1651:32)
at Module._load (node:internal/modules/cjs/loader:1443:12)
at wrapModuleLoad (node:internal/modules/cjs/loader:261:19)
at loadCJSModuleWithModuleLoad (node:internal/modules/esm/translators:372:15)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:244:9)
at ModuleJob.run (node:internal/modules/esm/module_job:561:25)
at async node:internal/modules/esm/loader:647:26
$ echo $?
2v7 で直すと
$ npm install -D eslint typescript-eslint
added 93 packages in 2s
$ echo $?
0$ npm ls typescript
both@1.0.0 /work/both
+-- ts-node@10.9.2
| `-- typescript@npm:@typescript/typescript6@6.0.2 deduped
+-- typescript-eslint@8.72.1
| +-- @typescript-eslint/eslint-plugin@8.72.1
| | +-- @typescript-eslint/type-utils@8.72.1
| | | `-- typescript@npm:@typescript/typescript6@6.0.2 deduped
| | +-- ts-api-utils@2.5.0
| | | `-- typescript@npm:@typescript/typescript6@6.0.2 deduped
| | `-- typescript@npm:@typescript/typescript6@6.0.2 deduped
| +-- @typescript-eslint/parser@8.72.1
| | `-- typescript@npm:@typescript/typescript6@6.0.2 deduped
| +-- @typescript-eslint/typescript-estree@8.72.1
| | +-- @typescript-eslint/project-service@8.72.1
| | | `-- typescript@npm:@typescript/typescript6@6.0.2 deduped
| | +-- @typescript-eslint/tsconfig-utils@8.72.1
| | | `-- typescript@npm:@typescript/typescript6@6.0.2 deduped
| | `-- typescript@npm:@typescript/typescript6@6.0.2 deduped
| +-- @typescript-eslint/utils@8.72.1
| | `-- typescript@npm:@typescript/typescript6@6.0.2 deduped
| `-- typescript@npm:@typescript/typescript6@6.0.2 deduped
`-- typescript@npm:@typescript/typescript6@6.0.2$ npx eslint src
$ echo $?
0ts-node と同じエイリアスで typescript に 6.0 を割り当てる。npm ls typescript を打つと、typescript-eslint の依存がすべて @typescript/typescript6 を指していることが分かる。
公式のアナウンスは、7.1 で今とは別の新しい API が出る見込みだと書いている。
typescript-eslint のエラーに出る issue は、7.1 以降への対応を追うためのものである。
JSDoc の @enum が型として使えなくなった
JavaScript を checkJs で検査しているとき、6.0 までは @enum を付けた値の名前を JSDoc の型として書けた。
7.0 では @enum に特別な意味が無くなり、値の名前を型の位置に書くと TS2749 になる。
v6 では
$ cat src/color.js
/** @enum {string} */
export const Color = { Red: "red", Blue: "blue" };
/** @param {Color} c */
export function paint(c) {
return c.toUpperCase();
}$ npx tsc -p .
$ echo $?
0v7 に上げると
$ npx tsc -p .
src/color.js(4,13): error TS2749: 'Color' refers to a value, but is being used as a type here. Did you mean 'typeof Color'?
$ echo $?
1v7 で直すと
$ cat src/color.js
export const Color = { Red: "red", Blue: "blue" };
/** @typedef {(typeof Color)[keyof typeof Color]} Color */
/** @param {Color} c */
export function paint(c) {
return c.toUpperCase();
}$ npx tsc -p .
$ echo $?
0値とは別に、@typedef で型を作る。
公式のアナウンスも、typeof と keyof で作った型に @typedef を付ける直し方を示している。(typeof Color)[keyof typeof Color] は Color のプロパティの型を集めた型である。as const を付けていないこの例では string になり、6.0 の @enum {string} と同じ意味になる。
値と同じ名前の型を作れるので、@param {Color} のように型を使う側は書き換えずに済む。
Closure 形式の JSDoc の型が読めなくなった
Google Closure Compiler の書き方の JSDoc は、7.0 で多くが読めなくなった。
ここで打ったのは、function(string): number のような関数の型と、? だけの型(何でもよいことを示す)である。
v6 では
$ cat src/util.js
/** @type {function(string): number} */
export const len = (s) => s.length;
/** @param {?} value */
export function show(value) {
console.log(value);
}$ npx tsc -p .
$ echo $?
0v7 に上げると
$ npx tsc -p .
src/util.js(1,20): error TS1005: '}' expected.
src/util.js(2,21): error TS7006: Parameter 's' implicitly has an 'any' type.
src/util.js(4,14): error TS1110: Type expected.
$ echo $?
1v7 で直すと
$ cat src/util.js
/** @type {(s: string) => number} */
export const len = (s) => s.length;
/** @param {any} value */
export function show(value) {
console.log(value);
}$ npx tsc -p .
$ echo $?
0関数の型は (s: string) => number のようにアロー関数の形で書き、? は any に書き換える。
公式のアナウンスによると、@class を付けた関数をコンストラクタとして扱うことと、型の後ろに付ける ! も 7.0 で無くなった(打っていない)。
JavaScript の扱いの違いは、アナウンスの JavaScript の節と typescript-go の CHANGES.md(新しいタブで開く) に一覧がある。
検証環境Node.js 24.22.2 / npm 11.19.1 / Python 3.11.2 / 2026-11-08 検証(ほか 7 件)
- 検証日
- 実行環境
node:24Debian GNU/Linux 12 (bookworm)- バージョン
- Node.js 24.22.2
- npm 11.19.1
- Python 3.11.2
- Git 2.39.5
- TypeScript(旧) 6.0.3
- TypeScript(新) 7.0.2
- ts-node 10.9.2
- typescript-eslint 8.72.1
- ESLint 10.14.0
- @typescript/typescript6 6.0.2
この記事の「実行例」は、上記の環境で実際にコマンドを実行して得られた出力をそのまま掲載しています。 再現手順はリポジトリの検証スクリプトとして管理し、定期的に再実行して出力を更新しています。