build: upgrade to TypeScript 7 (#54172)

TypeScript 7.0 is the native compiler and ships no JavaScript API. The
earlier changes in this series already moved everything that transpiled
on the fly (script/ and spec/) onto Node's own type stripping, so what
is left here is the compiler swap itself:

* typescript ^5.8.3 -> ^7.0.2.
* build/bundle/typecheck.mjs spawns tsc instead of driving the compiler
  API (the rootDir/private-field diagnostics it used to filter out are
  handled by tsconfig.electron.json setting rootDir to the parent
  checkout instead).
* tsconfig.json drops the removed baseUrl option and anchors the paths
  mapping explicitly; tsconfig.default_app.json moves off the removed
  "node" module resolution; `declare module NodeJS` becomes a namespace.
* A few lib/, spec and docs snippets wrap Buffers for the stricter
  Buffer/ArrayBuffer typings that Blob now expects.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Samuel AttardandClaude authored and GitHub committed 2026-09-21 15:21:32 -07:00
1 parent 9baaed782e
commit 8a6429e414
12 files changed
+293 -59

No files matched your search

+8 -36
View File
@@ -3,8 +3,7 @@
//
// node build/bundle/typecheck.mjs --project tsconfig.electron.json [--stamp file]
import ts from 'typescript';
import { spawnSync } from 'node:child_process';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { parseArgs } from 'node:util';
@@ -21,41 +20,14 @@ if (!args.project) {
throw new Error('--project is required');
}
// Diagnostics that come with pulling type information out of
// ../third_party/electron_node/lib/*.js via the `@node/*` path mapping.
const ignoredDiagnostics = new Set([
// File '{0}' is not under 'rootDir' '{1}'.
6059,
// Private field '{0}' must be declared in an enclosing class.
1111
]);
const formatHost = {
getCanonicalFileName: (fileName) => fileName,
getCurrentDirectory: ts.sys.getCurrentDirectory,
getNewLine: () => ts.sys.newLine
};
const reportAndExit = (diagnostics) => {
console.error(ts.formatDiagnosticsWithColorAndContext(diagnostics, formatHost));
process.exit(1);
};
const configFile = path.resolve(args.project);
const config = ts.getParsedCommandLineOfConfigFile(
configFile,
{ noEmit: true },
{ ...ts.sys, onUnRecoverableConfigFileDiagnostic: (diagnostic) => reportAndExit([diagnostic]) }
const tsc = path.resolve(import.meta.dirname, '..', '..', 'node_modules', 'typescript', 'bin', 'tsc');
const { status, error } = spawnSync(
process.execPath,
[tsc, '--project', path.resolve(args.project), '--noEmit', '--pretty'],
{ stdio: 'inherit' }
);
if (config.errors.length) reportAndExit(config.errors);
const program = ts.createProgram({
rootNames: config.fileNames,
options: config.options,
projectReferences: config.projectReferences
});
const diagnostics = ts.getPreEmitDiagnostics(program).filter((diagnostic) => !ignoredDiagnostics.has(diagnostic.code));
if (diagnostics.length) reportAndExit(diagnostics);
if (error) throw error;
if (status !== 0) process.exit(status ?? 1);
// An existing stamp is left untouched: its dependents only need to rebuild when
// their own sources change, and ninja (GN actions are restat) can then tell.
+1 -1
View File
@@ -65,7 +65,7 @@ clipboard.write([
new ClipboardItem({
'text/plain': 'hello',
'text/html': '<b>hello</b>',
'image/png': new Blob([png], { type: 'image/png' }),
'image/png': new Blob([new Uint8Array(png)], { type: 'image/png' }),
'electron application/bookmark': {
title: 'Electron',
url: 'https://electronjs.org'
+1 -1
View File
@@ -174,7 +174,7 @@ async function writeClipboard() {
new ClipboardItem({
'text/plain': 'hello',
'text/html': '<b>hello</b>',
'image/png': new Blob([png], { type: 'image/png' }),
'image/png': new Blob([new Uint8Array(png)], { type: 'image/png' }),
'electron application/bookmark': {
title: 'Electron',
url: 'https://electronjs.org'
+1 -1
View File
@@ -157,7 +157,7 @@ export class WebSocket extends EventTarget {
// sized exactly to the message, so .buffer is safe to expose.
payload = data.buffer as ArrayBuffer;
} else if (this[kBinaryType] === 'blob') {
payload = new Blob([data]);
payload = new Blob([data as Buffer<ArrayBuffer>]);
} else {
payload = data;
}
+1 -1
View File
@@ -61,7 +61,7 @@ const { codes: errorCodes } = require('internal/errors') as typeof import('@node
// In the renderer node internals use the node global URL but we do not set that to be
// the global URL instance. We need to do instanceof checks against the internal URL impl
const { URL: NodeURL } = require('internal/url') as typeof import('@node/lib/internal/url');
const { URL: NodeURL } = require('internal/url') as typeof import('node:url');
type SplitPathResult = { isAsar: false } | { isAsar: true; asarPath: string; filePath: string };
+1 -1
View File
@@ -32,7 +32,7 @@
"semver": "^7.6.3",
"stream-json": "^1.9.1",
"tap-xunit": "^2.4.1",
"typescript": "^5.8.3",
"typescript": "^7.0.2",
"yaml": "^2.8.1"
},
"private": true,
+2 -2
View File
@@ -64,7 +64,7 @@ describe('clipboard module', () => {
it('round-trips a NativeImage through the image/* MIME type', async () => {
const p = path.join(fixtures, 'assets', 'logo.png');
const i = nativeImage.createFromPath(p);
await clipboard.write([new ClipboardItem({ 'image/png': new Blob([i.toPNG()]) })]);
await clipboard.write([new ClipboardItem({ 'image/png': new Blob([new Uint8Array(i.toPNG())]) })]);
const buffer = await readType('image/png');
expect(buffer).to.be.an.instanceOf(Buffer);
@@ -221,7 +221,7 @@ describe('clipboard module', () => {
'text/plain': text,
'text/html': '<b>Hi</b>',
'text/rtf': rtf,
'image/png': new Blob([i.toPNG()]),
'image/png': new Blob([new Uint8Array(i.toPNG())]),
[BOOKMARK_MIME]: bookmark
})
]);
+1 -1
View File
@@ -3,7 +3,7 @@
"compilerOptions": {
"rootDir": "default_app",
"module": "ESNext",
"moduleResolution": "node"
"moduleResolution": "bundler"
},
"include": [
"default_app",
+2 -1
View File
@@ -1,7 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "lib"
"noEmit": true,
"rootDir": ".."
},
"include": [
"lib",
+1 -2
View File
@@ -10,13 +10,12 @@
"sourceMap": true,
"experimentalDecorators": true,
"strict": true,
"baseUrl": ".",
"allowJs": true,
"noUnusedLocals": true,
"outDir": "ts-gen",
"typeRoots" : ["./node_modules/@types", "./spec/node_modules/@types"],
"paths": {
"@electron/internal/*": ["lib/*"],
"@electron/internal/*": ["./lib/*"],
"@node/*": ["../third_party/electron_node/*"]
}
},
+1 -1
View File
@@ -355,7 +355,7 @@ declare namespace NodeJS {
}
}
declare module NodeJS {
declare namespace NodeJS {
interface Global {
require: NodeRequire;
module: NodeModule;
+273 -11
View File
@@ -303,7 +303,7 @@ __metadata:
semver: "npm:^7.6.3"
stream-json: "npm:^1.9.1"
tap-xunit: "npm:^2.4.1"
typescript: "npm:^5.8.3"
typescript: "npm:^7.0.2"
yaml: "npm:^2.8.1"
dependenciesMeta:
"@sentry/cli":
@@ -1649,6 +1649,146 @@ __metadata:
languageName: node
linkType: hard
"@typescript/typescript-aix-ppc64@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-aix-ppc64@npm:7.0.2"
conditions: os=aix & cpu=ppc64
languageName: node
linkType: hard
"@typescript/typescript-darwin-arm64@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-darwin-arm64@npm:7.0.2"
conditions: os=darwin & cpu=arm64
languageName: node
linkType: hard
"@typescript/typescript-darwin-x64@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-darwin-x64@npm:7.0.2"
conditions: os=darwin & cpu=x64
languageName: node
linkType: hard
"@typescript/typescript-freebsd-arm64@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-freebsd-arm64@npm:7.0.2"
conditions: os=freebsd & cpu=arm64
languageName: node
linkType: hard
"@typescript/typescript-freebsd-x64@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-freebsd-x64@npm:7.0.2"
conditions: os=freebsd & cpu=x64
languageName: node
linkType: hard
"@typescript/typescript-linux-arm64@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-linux-arm64@npm:7.0.2"
conditions: os=linux & cpu=arm64
languageName: node
linkType: hard
"@typescript/typescript-linux-arm@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-linux-arm@npm:7.0.2"
conditions: os=linux & cpu=arm
languageName: node
linkType: hard
"@typescript/typescript-linux-loong64@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-linux-loong64@npm:7.0.2"
conditions: os=linux & cpu=loong64
languageName: node
linkType: hard
"@typescript/typescript-linux-mips64el@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-linux-mips64el@npm:7.0.2"
conditions: os=linux & cpu=mips64el
languageName: node
linkType: hard
"@typescript/typescript-linux-ppc64@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-linux-ppc64@npm:7.0.2"
conditions: os=linux & cpu=ppc64
languageName: node
linkType: hard
"@typescript/typescript-linux-riscv64@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-linux-riscv64@npm:7.0.2"
conditions: os=linux & cpu=riscv64
languageName: node
linkType: hard
"@typescript/typescript-linux-s390x@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-linux-s390x@npm:7.0.2"
conditions: os=linux & cpu=s390x
languageName: node
linkType: hard
"@typescript/typescript-linux-x64@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-linux-x64@npm:7.0.2"
conditions: os=linux & cpu=x64
languageName: node
linkType: hard
"@typescript/typescript-netbsd-arm64@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-netbsd-arm64@npm:7.0.2"
conditions: os=netbsd & cpu=arm64
languageName: node
linkType: hard
"@typescript/typescript-netbsd-x64@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-netbsd-x64@npm:7.0.2"
conditions: os=netbsd & cpu=x64
languageName: node
linkType: hard
"@typescript/typescript-openbsd-arm64@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-openbsd-arm64@npm:7.0.2"
conditions: os=openbsd & cpu=arm64
languageName: node
linkType: hard
"@typescript/typescript-openbsd-x64@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-openbsd-x64@npm:7.0.2"
conditions: os=openbsd & cpu=x64
languageName: node
linkType: hard
"@typescript/typescript-sunos-x64@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-sunos-x64@npm:7.0.2"
conditions: os=sunos & cpu=x64
languageName: node
linkType: hard
"@typescript/typescript-win32-arm64@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-win32-arm64@npm:7.0.2"
conditions: os=win32 & cpu=arm64
languageName: node
linkType: hard
"@typescript/typescript-win32-x64@npm:7.0.2":
version: 7.0.2
resolution: "@typescript/typescript-win32-x64@npm:7.0.2"
conditions: os=win32 & cpu=x64
languageName: node
linkType: hard
"@typespec/ts-http-runtime@npm:^0.3.0, @typespec/ts-http-runtime@npm:^0.3.4":
version: 0.3.8
resolution: "@typespec/ts-http-runtime@npm:0.3.8"
@@ -4751,23 +4891,145 @@ __metadata:
languageName: node
linkType: hard
"typescript@npm:^5.8.3":
version: 5.8.3
resolution: "typescript@npm:5.8.3"
"typescript@npm:^7.0.2":
version: 7.0.2
resolution: "typescript@npm:7.0.2"
dependencies:
"@typescript/typescript-aix-ppc64": "npm:7.0.2"
"@typescript/typescript-darwin-arm64": "npm:7.0.2"
"@typescript/typescript-darwin-x64": "npm:7.0.2"
"@typescript/typescript-freebsd-arm64": "npm:7.0.2"
"@typescript/typescript-freebsd-x64": "npm:7.0.2"
"@typescript/typescript-linux-arm": "npm:7.0.2"
"@typescript/typescript-linux-arm64": "npm:7.0.2"
"@typescript/typescript-linux-loong64": "npm:7.0.2"
"@typescript/typescript-linux-mips64el": "npm:7.0.2"
"@typescript/typescript-linux-ppc64": "npm:7.0.2"
"@typescript/typescript-linux-riscv64": "npm:7.0.2"
"@typescript/typescript-linux-s390x": "npm:7.0.2"
"@typescript/typescript-linux-x64": "npm:7.0.2"
"@typescript/typescript-netbsd-arm64": "npm:7.0.2"
"@typescript/typescript-netbsd-x64": "npm:7.0.2"
"@typescript/typescript-openbsd-arm64": "npm:7.0.2"
"@typescript/typescript-openbsd-x64": "npm:7.0.2"
"@typescript/typescript-sunos-x64": "npm:7.0.2"
"@typescript/typescript-win32-arm64": "npm:7.0.2"
"@typescript/typescript-win32-x64": "npm:7.0.2"
dependenciesMeta:
"@typescript/typescript-aix-ppc64":
optional: true
"@typescript/typescript-darwin-arm64":
optional: true
"@typescript/typescript-darwin-x64":
optional: true
"@typescript/typescript-freebsd-arm64":
optional: true
"@typescript/typescript-freebsd-x64":
optional: true
"@typescript/typescript-linux-arm":
optional: true
"@typescript/typescript-linux-arm64":
optional: true
"@typescript/typescript-linux-loong64":
optional: true
"@typescript/typescript-linux-mips64el":
optional: true
"@typescript/typescript-linux-ppc64":
optional: true
"@typescript/typescript-linux-riscv64":
optional: true
"@typescript/typescript-linux-s390x":
optional: true
"@typescript/typescript-linux-x64":
optional: true
"@typescript/typescript-netbsd-arm64":
optional: true
"@typescript/typescript-netbsd-x64":
optional: true
"@typescript/typescript-openbsd-arm64":
optional: true
"@typescript/typescript-openbsd-x64":
optional: true
"@typescript/typescript-sunos-x64":
optional: true
"@typescript/typescript-win32-arm64":
optional: true
"@typescript/typescript-win32-x64":
optional: true
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/5f8bb01196e542e64d44db3d16ee0e4063ce4f3e3966df6005f2588e86d91c03e1fb131c2581baf0fb65ee79669eea6e161cd448178986587e9f6844446dbb48
checksum: 10c0/3dcee51ec8c332492325bcdbf7df48b66668751f127e622ae7d41b6c716eb19184424a45e14f7750f50f340232388b69e6287859155f06a5ce2df76f12cb31cf
languageName: node
linkType: hard
"typescript@patch:typescript@npm%3A^5.8.3#optional!builtin<compat/typescript>":
version: 5.8.3
resolution: "typescript@patch:typescript@npm%3A5.8.3#optional!builtin<compat/typescript>::version=5.8.3&hash=5786d5"
"typescript@patch:typescript@npm%3A^7.0.2#optional!builtin<compat/typescript>":
version: 7.0.2
resolution: "typescript@patch:typescript@npm%3A7.0.2#optional!builtin<compat/typescript>::version=7.0.2&hash=3bafbf"
dependencies:
"@typescript/typescript-aix-ppc64": "npm:7.0.2"
"@typescript/typescript-darwin-arm64": "npm:7.0.2"
"@typescript/typescript-darwin-x64": "npm:7.0.2"
"@typescript/typescript-freebsd-arm64": "npm:7.0.2"
"@typescript/typescript-freebsd-x64": "npm:7.0.2"
"@typescript/typescript-linux-arm": "npm:7.0.2"
"@typescript/typescript-linux-arm64": "npm:7.0.2"
"@typescript/typescript-linux-loong64": "npm:7.0.2"
"@typescript/typescript-linux-mips64el": "npm:7.0.2"
"@typescript/typescript-linux-ppc64": "npm:7.0.2"
"@typescript/typescript-linux-riscv64": "npm:7.0.2"
"@typescript/typescript-linux-s390x": "npm:7.0.2"
"@typescript/typescript-linux-x64": "npm:7.0.2"
"@typescript/typescript-netbsd-arm64": "npm:7.0.2"
"@typescript/typescript-netbsd-x64": "npm:7.0.2"
"@typescript/typescript-openbsd-arm64": "npm:7.0.2"
"@typescript/typescript-openbsd-x64": "npm:7.0.2"
"@typescript/typescript-sunos-x64": "npm:7.0.2"
"@typescript/typescript-win32-arm64": "npm:7.0.2"
"@typescript/typescript-win32-x64": "npm:7.0.2"
dependenciesMeta:
"@typescript/typescript-aix-ppc64":
optional: true
"@typescript/typescript-darwin-arm64":
optional: true
"@typescript/typescript-darwin-x64":
optional: true
"@typescript/typescript-freebsd-arm64":
optional: true
"@typescript/typescript-freebsd-x64":
optional: true
"@typescript/typescript-linux-arm":
optional: true
"@typescript/typescript-linux-arm64":
optional: true
"@typescript/typescript-linux-loong64":
optional: true
"@typescript/typescript-linux-mips64el":
optional: true
"@typescript/typescript-linux-ppc64":
optional: true
"@typescript/typescript-linux-riscv64":
optional: true
"@typescript/typescript-linux-s390x":
optional: true
"@typescript/typescript-linux-x64":
optional: true
"@typescript/typescript-netbsd-arm64":
optional: true
"@typescript/typescript-netbsd-x64":
optional: true
"@typescript/typescript-openbsd-arm64":
optional: true
"@typescript/typescript-openbsd-x64":
optional: true
"@typescript/typescript-sunos-x64":
optional: true
"@typescript/typescript-win32-arm64":
optional: true
"@typescript/typescript-win32-x64":
optional: true
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/39117e346ff8ebd87ae1510b3a77d5d92dae5a89bde588c747d25da5c146603a99c8ee588c7ef80faaf123d89ed46f6dbd918d534d641083177d5fac38b8a1cb
checksum: 10c0/6b3cdc369cd829d46e00734ea64233ee84419c2825ad8fe408915adde77abced4b7a2401f7eed517d54a7a4f5d1c1869753cb99018df1c2159c761d9f33483a6
languageName: node
linkType: hard