Skip to content

Upgrade TypeScript to v5.5.2 #67113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
"tree-kill": "1.2.2",
"tsec": "0.2.1",
"turbo": "2.0.6-canary.0",
"typescript": "5.4.5",
"typescript": "5.5.2",
"unfetch": "4.2.0",
"wait-port": "0.2.2",
"webpack": "5.90.0",
Expand Down
1 change: 1 addition & 0 deletions packages/next/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference types="./types/global" />
/// <reference types="./types/compiled" />
/// <reference path="./dist/styled-jsx/types/index.d.ts" />
/// <reference path="./amp.d.ts" />
/// <reference path="./app.d.ts" />
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@
"util": "0.12.4",
"vm-browserify": "1.1.2",
"watchpack": "2.4.0",
"web-vitals": "3.0.0",
"web-vitals": "4.2.1",
"webpack": "5.90.0",
"webpack-sources1": "npm:[email protected]",
"webpack-sources3": "npm:[email protected]",
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/next/src/compiled/web-vitals/web-vitals.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/next/src/server/app-render/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ async function createForwardedActionResponse(
const fetchUrl = new URL(`${origin}${basePath}${workerPathname}`)

try {
let body: BodyInit | AsyncIterable<any> | undefined
let body: BodyInit | ReadableStream<Uint8Array> | undefined
if (
// The type check here ensures that `req` is correctly typed, and the
// environment variable check provides dead code elimination.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ export async function streamToBuffer(
): Promise<Buffer> {
const buffers: Buffer[] = []

// @ts-expect-error TypeScript gets this wrong (https://nodejs.org/api/webstreams.html#async-iteration)
for await (const chunk of stream) {
buffers.push(chunk)
buffers.push(Buffer.from(chunk))
}

return Buffer.concat(buffers)
Expand All @@ -101,7 +100,6 @@ export async function streamToString(
const decoder = new TextDecoder('utf-8', { fatal: true })
let string = ''

// @ts-expect-error TypeScript gets this wrong (https://nodejs.org/api/webstreams.html#async-iteration)
for await (const chunk of stream) {
string += decoder.decode(chunk, { stream: true })
}
Expand Down
10 changes: 5 additions & 5 deletions packages/next/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// <reference types="node" />
/// <reference types="react" />
/// <reference types="react/experimental" />
/// <reference types="react-dom" />
/// <reference types="react-dom/experimental" />
/// <reference types="node" preserve="true" />
/// <reference types="react" preserve="true" />
/// <reference types="react/experimental" preserve="true" />
/// <reference types="react-dom" preserve="true" />
/// <reference types="react-dom/experimental" preserve="true" />

Comment on lines +1 to +5
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking for something like this the last time. Nice find 👍🏻 The TS team is not the only team missing docs 😄

import type { Agent as HttpAgent } from 'http'
import type { Agent as HttpsAgent } from 'https'
Expand Down
36 changes: 1 addition & 35 deletions packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2589,10 +2589,7 @@ export async function diagnostics(task, opts) {
}

export async function build(task, opts) {
await task.serial(
['precompile', 'compile', 'generate_types', 'rewrite_compiled_references'],
opts
)
await task.serial(['precompile', 'compile', 'generate_types'], opts)
}

export async function generate_types(task, opts) {
Expand All @@ -2601,37 +2598,6 @@ export async function generate_types(task, opts) {
})
}

/**
* TypeScript will emit references to the compiled types used to type the implementation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript no longer does that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a good amount of time to debug from error caused by this 😅, TS didn't generate
/// <reference path="../../../../types/$$compiled.internal.d.ts" /> for related files as they used to.

Currently looking for a backup docs about why, but for now found on the PR:

References are no longer preserved in the output from the input, nor are they ever added based on any analysis.

* The declarations however don't need such detailed types.
* We rewrite the references to reference a more lightweight solution instead.
* @param {import('taskr').Task} task
*/
export async function rewrite_compiled_references(task, opts) {
const declarationDirectory = join(__dirname, 'dist')
const declarationFiles = glob.sync('**/*.d.ts', { cwd: declarationDirectory })

for (const declarationFile of declarationFiles) {
const content = await fs.readFile(
join(declarationDirectory, declarationFile),
'utf8'
)
// Rewrite
// /// <reference path="../../../../types/$$compiled.internal.d.ts" />
// to
// /// <reference path="../../../../types/compiled.d.ts" />
if (content.indexOf('/types/$$compiled.internal.d.ts" />') !== -1) {
await fs.writeFile(
join(declarationDirectory, declarationFile),
content.replace(
/\/types\/\$\$compiled\.internal\.d\.ts" \/>/g,
'/types/compiled.d.ts" />'
)
)
}
}
}

export default async function (task) {
const opts = { dev: true }
await task.clear('dist')
Expand Down
10 changes: 5 additions & 5 deletions packages/next/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"extends": "../../tsconfig-tsec.json",
"compilerOptions": {
"strict": true,
"module": "esnext",
"target": "ES2017",
"stripInternal": true,
"esModuleInterop": true,
"moduleResolution": "node",
"verbatimModuleSyntax": true,
"jsx": "react-jsx",
"stripInternal": true,
"verbatimModuleSyntax": true
"module": "ESNext",
"target": "ES2018",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically no change but target ES2017 -> ES2018, sorry for moving around order. 😅

Why?

why_tsconfig_target_es2018

"moduleResolution": "node"
},
"exclude": [
"dist",
Expand Down
7 changes: 0 additions & 7 deletions packages/next/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
// Triple slash directives are copied from src/types.ts.
// TypeScript currently does not preserve the tripple-slash directives.
// Once https://github.com/microsoft/TypeScript/pull/57681 is released, we can remove the triple slash directives here.
/// <reference types="react" />
/// <reference types="react/experimental" />
/// <reference types="react-dom" />
/// <reference types="react-dom/experimental" />
export * from './dist/types'
export { default } from './dist/types'
Loading
Loading