From d5bc63b326c1b58934018074bbf93da179ce32c5 Mon Sep 17 00:00:00 2001 From: "Sebastian \"Sebbie\" Silbermann" Date: Wed, 1 Oct 2025 19:02:38 +0200 Subject: [PATCH 1/4] [react-dom] Add types for `headersLengthHint`, `importMap` and `onHeaders` to /server and /static rendering APIs (#73766) --- types/react-dom/server.d.ts | 48 +++++++++++++++++- types/react-dom/static.d.ts | 40 ++++++++++++++- types/react-dom/test/react-dom-tests.tsx | 63 ++++++++++++++++++++++-- 3 files changed, 143 insertions(+), 8 deletions(-) diff --git a/types/react-dom/server.d.ts b/types/react-dom/server.d.ts index 0b25650a633745..f5fac9a041d13e 100644 --- a/types/react-dom/server.d.ts +++ b/types/react-dom/server.d.ts @@ -24,11 +24,39 @@ declare global { import { ReactNode } from "react"; import { ErrorInfo, ReactFormState } from "./client"; -export type BootstrapScriptDescriptor = { +export interface BootstrapScriptDescriptor { src: string; integrity?: string | undefined; crossOrigin?: string | undefined; -}; +} + +/** + * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap Import maps} + */ +// TODO: Ideally TypeScripts standard library would include this type. +// Until then we keep the prefixed one for future compatibility. +export interface ReactImportMap { + /** + * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap#imports `imports` reference} + */ + imports?: { + [specifier: string]: string; + } | undefined; + /** + * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap#integrity `integrity` reference} + */ + integrity?: { + [moduleURL: string]: string; + } | undefined; + /** + * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap#scopes `scopes` reference} + */ + scopes?: { + [scope: string]: { + [specifier: string]: string; + }; + } | undefined; +} export interface RenderToPipeableStreamOptions { identifierPrefix?: string; @@ -37,7 +65,15 @@ export interface RenderToPipeableStreamOptions { bootstrapScriptContent?: string; bootstrapScripts?: Array; bootstrapModules?: Array; + /** + * Maximum length of the header content in unicode code units i.e. string.length. + * Must be a positive integer if specified. + * @default 2000 + */ + headersLengthHint?: number | undefined; + importMap?: ReactImportMap | undefined; progressiveChunkSize?: number; + onHeaders?: ((headers: Headers) => void) | undefined; onShellReady?: () => void; onShellError?: (error: unknown) => void; onAllReady?: () => void; @@ -86,14 +122,22 @@ export function renderToStaticMarkup(element: ReactNode, options?: ServerOptions export interface RenderToReadableStreamOptions { identifierPrefix?: string; + importMap?: ReactImportMap | undefined; namespaceURI?: string; nonce?: string; bootstrapScriptContent?: string; bootstrapScripts?: Array; bootstrapModules?: Array; + /** + * Maximum length of the header content in unicode code units i.e. string.length. + * Must be a positive integer if specified. + * @default 2000 + */ + headersLengthHint?: number | undefined; progressiveChunkSize?: number; signal?: AbortSignal; onError?: (error: unknown, errorInfo: ErrorInfo) => string | void; + onHeaders?: ((headers: Headers) => void) | undefined; formState?: ReactFormState | null; } diff --git a/types/react-dom/static.d.ts b/types/react-dom/static.d.ts index ef52180c8f9c77..4a42b58a1d09b8 100644 --- a/types/react-dom/static.d.ts +++ b/types/react-dom/static.d.ts @@ -27,19 +27,55 @@ declare global { import { ReactNode } from "react"; import { ErrorInfo } from "./client"; -export type BootstrapScriptDescriptor = { +/** + * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap Import maps} + */ +// TODO: Ideally TypeScripts standard library would include this type. +// Until then we keep the prefixed one for future compatibility. +export interface ReactImportMap { + /** + * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap#imports `imports` reference} + */ + imports?: { + [specifier: string]: string; + } | undefined; + /** + * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap#integrity `integrity` reference} + */ + integrity?: { + [moduleURL: string]: string; + } | undefined; + /** + * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap#scopes `scopes` reference} + */ + scopes?: { + [scope: string]: { + [specifier: string]: string; + }; + } | undefined; +} + +export interface BootstrapScriptDescriptor { src: string; integrity?: string | undefined; crossOrigin?: string | undefined; -}; +} export interface PrerenderOptions { bootstrapScriptContent?: string; bootstrapScripts?: Array; bootstrapModules?: Array; + /** + * Maximum length of the header content in unicode code units i.e. string.length. + * Must be a positive integer if specified. + * @default 2000 + */ + headersLengthHint?: number | undefined; identifierPrefix?: string; + importMap?: ImportMap | undefined; namespaceURI?: string; onError?: (error: unknown, errorInfo: ErrorInfo) => string | void; + onHeaders?: (headers: Headers) => void | undefined; progressiveChunkSize?: number; signal?: AbortSignal; } diff --git a/types/react-dom/test/react-dom-tests.tsx b/types/react-dom/test/react-dom-tests.tsx index 2961231983bab2..c45b6b401f91c2 100644 --- a/types/react-dom/test/react-dom-tests.tsx +++ b/types/react-dom/test/react-dom-tests.tsx @@ -45,15 +45,30 @@ describe("ReactDOM", () => { }); }); +const importMap: ReactDOMStatic.ReactImportMap = { + imports: { + "moduleA": "/modules/moduleA.v1.0.0.js", + }, + scopes: { + "/modules/": { + "moduleB": "/modules/moduleB.v1.0.0.js", + }, + }, +}; + describe("ReactDOMServer", () => { it("renderToString", () => { const content: string = ReactDOMServer.renderToString(React.createElement("div")); - ReactDOMServer.renderToString(React.createElement("div"), { identifierPrefix: "react-18-app" }); + ReactDOMServer.renderToString(React.createElement("div"), { + identifierPrefix: "react-18-app", + }); }); it("renderToStaticMarkup", () => { const content: string = ReactDOMServer.renderToStaticMarkup(React.createElement("div")); - ReactDOMServer.renderToStaticMarkup(React.createElement("div"), { identifierPrefix: "react-18-app" }); + ReactDOMServer.renderToStaticMarkup(React.createElement("div"), { + identifierPrefix: "react-18-app", + }); }); }); @@ -61,13 +76,29 @@ describe("ReactDOMStatic", () => { it("prerender", async () => { const prelude: ReadableStream = (await ReactDOMStatic.prerender(React.createElement("div"))).prelude; - ReactDOMStatic.prerender(React.createElement("div"), { bootstrapScripts: ["./my-script.js"] }); + ReactDOMStatic.prerender(React.createElement("div"), { + bootstrapScripts: ["./my-script.js"], + headersLengthHint: 4000, + importMap, + onHeaders(headers) { + // $ExpectType Headers + headers; + }, + }); }); it("prerenderToNodeStream", async () => { const prelude: NodeJS.ReadableStream = (await ReactDOMStatic.prerenderToNodeStream(React.createElement("div"))).prelude; - ReactDOMStatic.prerenderToNodeStream(React.createElement("div"), { bootstrapScripts: ["./my-script.js"] }); + ReactDOMStatic.prerenderToNodeStream(React.createElement("div"), { + bootstrapScripts: ["./my-script.js"], + headersLengthHint: 4000, + importMap, + onHeaders(headers) { + // $ExpectType Headers + headers; + }, + }); }); }); @@ -207,6 +238,12 @@ function pipeableStreamDocumentedExample() { const response: Response = {} as any; const { pipe, abort } = ReactDOMServer.renderToPipeableStream(, { bootstrapScripts: ["/main.js"], + headersLengthHint: 4000, + importMap, + onHeaders(headers) { + // $ExpectType Headers + headers; + }, onShellReady() { response.statusCode = didError ? 500 : 200; response.setHeader("content-type", "text/html"); @@ -254,6 +291,12 @@ function pipeableStreamDocumentedStringExample() { const response: Response = {} as any; const { pipe, abort } = ReactDOMServer.renderToPipeableStream("app", { bootstrapScripts: ["/main.js"], + headersLengthHint: 4000, + importMap, + onHeaders(headers) { + // $ExpectType Headers + headers; + }, onShellReady() { response.statusCode = didError ? 500 : 200; response.setHeader("content-type", "text/html"); @@ -295,11 +338,17 @@ async function readableStreamDocumentedExample() { Success , { + headersLengthHint: 4000, + importMap, signal: controller.signal, onError(error) { didError = true; console.error(error); }, + onHeaders(headers) { + // $ExpectType Headers + headers; + }, }, ); @@ -327,11 +376,17 @@ async function readableStreamDocumentedStringExample() { const stream = await ReactDOMServer.renderToReadableStream( "app", { + headersLengthHint: 4000, + importMap, signal: controller.signal, onError(error) { didError = true; console.error(error); }, + onHeaders(headers) { + // $ExpectType Headers + headers; + }, }, ); From fef412e3663c6053f1b5e3fb0a9b1bea20daa871 Mon Sep 17 00:00:00 2001 From: Erwan Jugand <47392755+erwanjugand@users.noreply.github.com> Date: Wed, 1 Oct 2025 20:05:08 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#73794=20[chrom?= =?UTF-8?q?e]=20update=20sidePanel=20namespace=20by=20@erwanjugand?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/chrome/index.d.ts | 113 +++++++++++++------------------------ types/chrome/test/index.ts | 96 ++++++++++++------------------- 2 files changed, 73 insertions(+), 136 deletions(-) diff --git a/types/chrome/index.d.ts b/types/chrome/index.d.ts index 4dc9ca0fa268ed..276d56e2698436 100644 --- a/types/chrome/index.d.ts +++ b/types/chrome/index.d.ts @@ -14103,27 +14103,26 @@ declare namespace chrome { * If specified, the side panel options for the given tab will be returned. * Otherwise, returns the default side panel options (used for any tab that doesn't have specific settings). */ - tabId?: number; + tabId?: number | undefined; } - /** - * @since Chrome 116 - */ + /** @since Chrome 116 */ export type OpenOptions = & { - /** The tab in which to open the side panel. + /** + * The tab in which to open the side panel. * If the corresponding tab has a tab-specific side panel, the panel will only be open for that tab. * If there is not a tab-specific panel, the global panel will be open in the specified tab and any other tabs without a currently-open tab- specific panel. * This will override any currently-active side panel (global or tab-specific) in the corresponding tab. - * At least one of this and windowId must be provided. */ - tabId?: number; + * At least one of this and `windowId` must be provided. */ + tabId?: number | undefined; /** * The window in which to open the side panel. - * This is only applicable if the extension has a global (non-tab-specific) side panel or tabId is also specified. + * This is only applicable if the extension has a global (non-tab-specific) side panel or `tabId` is also specified. * This will override any currently-active global side panel the user has open in the given window. - * At least one of this and tabId must be provided. + * At least one of this and `tabId` must be provided. */ - windowId?: number; + windowId?: number | undefined; } & ({ tabId: number; @@ -14133,7 +14132,7 @@ declare namespace chrome { export interface PanelBehavior { /** Whether clicking the extension's icon will toggle showing the extension's entry in the side panel. Defaults to false. */ - openPanelOnActionClick?: boolean; + openPanelOnActionClick?: boolean | undefined; } /** @since Chrome 140 */ @@ -14143,15 +14142,15 @@ declare namespace chrome { export interface PanelOptions { /** Whether the side panel should be enabled. This is optional. The default value is true. */ - enabled?: boolean; + enabled?: boolean | undefined; /** The path to the side panel HTML file to use. This must be a local resource within the extension package. */ - path?: string; + path?: string | undefined; /** * If specified, the side panel options will only apply to the tab with this id. * If omitted, these options set the default behavior (used for any tab that doesn't have specific settings). * Note: if the same path is set for this tabId and the default tabId, then the panel for this tabId will be a different instance than the panel for the default tabId. */ - tabId?: number; + tabId?: number | undefined; } /** @@ -14177,84 +14176,48 @@ declare namespace chrome { /** * Returns the active panel configuration. - * Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. - * You cannot use both on the same function call. - * The promise resolves with the same type that is passed to the callback. - */ - export function getOptions( - /** Specifies the context to return the configuration for. */ - options: GetPanelOptions, - callback: (options: PanelOptions) => void, - ): void; - - export function getOptions( - /** Specifies the context to return the configuration for. */ - options: GetPanelOptions, - ): Promise; + * + * Can return its result via Promise. + * @param options Specifies the context to return the configuration for. + */ + export function getOptions(options: GetPanelOptions): Promise; + export function getOptions(options: GetPanelOptions, callback: (options: PanelOptions) => void): void; /** * Returns the extension's current side panel behavior. - * Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. - * You cannot use both on the same function call. - * The promise resolves with the same type that is passed to the callback. + * + * Can return its result via Promise. */ - export function getPanelBehavior( - callback: (behavior: PanelBehavior) => void, - ): void; - export function getPanelBehavior(): Promise; + export function getPanelBehavior(callback: (behavior: PanelBehavior) => void): void; /** - * @since Chrome 116 * Opens the side panel for the extension. This may only be called in response to a user action. - * Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. - * You cannot use both on the same function call. - * The promise resolves with the same type that is passed to the callback. + * + * Can return its result via Promise. + * @param options Specifies the context in which to open the side panel. + * @since Chrome 116 */ - export function open( - /** Specifies the context in which to open the side panel. */ - options: OpenOptions, - callback: () => void, - ): void; - - export function open( - /** Specifies the context in which to open the side panel. */ - options: OpenOptions, - ): Promise; + export function open(options: OpenOptions): Promise; + export function open(options: OpenOptions, callback: () => void): void; /** * Configures the side panel. - * Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. - * You cannot use both on the same function call. - * The promise resolves with the same type that is passed to the callback. + * + * Can return its result via Promise. + * @param options The configuration options to apply to the panel. */ - export function setOptions( - /** The configuration options to apply to the panel. */ - options: PanelOptions, - callback: () => void, - ): void; - - export function setOptions( - /** The configuration options to apply to the panel. */ - options: PanelOptions, - ): Promise; + export function setOptions(options: PanelOptions): Promise; + export function setOptions(options: PanelOptions, callback: () => void): void; /** * Configures the extension's side panel behavior. This is an upsert operation. - * Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. - * You cannot use both on the same function call. - * The promise resolves with the same type that is passed to the callback. + * + * Can return its result via Promise. + * @param behavior The new behavior to be set. */ - export function setPanelBehavior( - /** The new behavior to be set. */ - behavior: PanelBehavior, - callback: () => void, - ): void; - - export function setPanelBehavior( - /** The new behavior to be set. */ - behavior: PanelBehavior, - ): Promise; + export function setPanelBehavior(behavior: PanelBehavior): Promise; + export function setPanelBehavior(behavior: PanelBehavior, callback: () => void): void; } //////////////////// diff --git a/types/chrome/test/index.ts b/types/chrome/test/index.ts index d02dce7150597a..e00fecb4a8d12e 100644 --- a/types/chrome/test/index.ts +++ b/types/chrome/test/index.ts @@ -5600,6 +5600,9 @@ function testSessions() { // https://developer.chrome.com/docs/extensions/reference/api/sidePanel function testSidePanel() { + chrome.sidePanel.Side.LEFT === "left"; + chrome.sidePanel.Side.RIGHT === "right"; + chrome.sidePanel.getLayout(); // $ExpectType Promise chrome.sidePanel.getLayout((layout) => { // $ExpectType void layout.side; // $ExpectType "left" | "right" @@ -5607,94 +5610,65 @@ function testSidePanel() { // @ts-expect-error chrome.sidePanel.getLayout(() => {}).then(() => {}); - let getPanelOptions: chrome.sidePanel.GetPanelOptions = { + const getPanelOptions: chrome.sidePanel.GetPanelOptions = { tabId: 123, }; - chrome.sidePanel.getOptions(getPanelOptions, (options: chrome.sidePanel.PanelOptions) => { - console.log("Using callback:"); - console.log(options.enabled); - console.log(options.path); - console.log(options.tabId); - }); - - chrome.sidePanel.getOptions(getPanelOptions).then((options: chrome.sidePanel.PanelOptions) => { - console.log("Using promise:"); - console.log(options.enabled); - console.log(options.path); - console.log(options.tabId); - }); - - chrome.sidePanel.getPanelBehavior((behavior: chrome.sidePanel.PanelBehavior) => { - console.log("Using callback:", behavior.openPanelOnActionClick); + chrome.sidePanel.getOptions(getPanelOptions); // $ExpectType Promise + chrome.sidePanel.getOptions(getPanelOptions, (options) => { // $ExpectType void + options.enabled; // $ExpectType boolean | undefined + options.path; // $ExpectType string | undefined + options.tabId; // $ExpectType number | undefined }); + // @ts-expect-error + chrome.sidePanel.getOptions(getPanelOptions, () => {}).then(() => {}); - chrome.sidePanel.getPanelBehavior().then((behavior) => { - console.log("Using promise:", behavior.openPanelOnActionClick); + chrome.sidePanel.getPanelBehavior(); // $ExpectType Promise + chrome.sidePanel.getPanelBehavior((behavior) => { // $ExpectType void + behavior.openPanelOnActionClick; // $ExpectType boolean | undefined }); + // @ts-expect-error + chrome.sidePanel.getPanelBehavior(() => {}).then(() => {}); - let openOptionsTab: chrome.sidePanel.OpenOptions = { + const openOptionsTab: chrome.sidePanel.OpenOptions = { tabId: 1234567890, }; - let openOptionsWindow: chrome.sidePanel.OpenOptions = { + const openOptionsWindow: chrome.sidePanel.OpenOptions = { windowId: 9876543210, }; - let openOptionsTabAndWindow: chrome.sidePanel.OpenOptions = { + const openOptionsTabAndWindow: chrome.sidePanel.OpenOptions = { tabId: 1234567890, windowId: 9876543210, }; - chrome.sidePanel.open(openOptionsTab, () => { - console.log("Side panel opened in tab using callback"); - }); - - chrome.sidePanel.open(openOptionsTab).then(() => { - console.log("Side panel opened in tab using promise"); - }); - - chrome.sidePanel.open(openOptionsWindow, () => { - console.log("Side panel opened in window using callback"); - }); - - chrome.sidePanel.open(openOptionsWindow).then(() => { - console.log("Side panel opened in window using promise"); - }); - - chrome.sidePanel.open(openOptionsTabAndWindow, () => { - console.log("Side panel opened in tab in window using callback"); - }); + chrome.sidePanel.open(openOptionsTab); // $ExpectType Promise + chrome.sidePanel.open(openOptionsWindow); // $ExpectType Promise + chrome.sidePanel.open(openOptionsTabAndWindow); // $ExpectType Promise + chrome.sidePanel.open(openOptionsTab, () => void 0); // $ExpectType void + chrome.sidePanel.open(openOptionsWindow, () => void 0); // $ExpectType void + chrome.sidePanel.open(openOptionsTabAndWindow, () => void 0); // $ExpectType void - chrome.sidePanel.open(openOptionsTabAndWindow).then(() => { - console.log("Side panel opened in tab in window using promise"); - }); - - let setPanelOptions: chrome.sidePanel.PanelOptions = { + const setPanelOptions: chrome.sidePanel.PanelOptions = { enabled: true, path: "path/to/sidePanel.html", tabId: 123, }; - chrome.sidePanel.setOptions(setPanelOptions, () => { - console.log("Options set successfully using callback."); - }); - - chrome.sidePanel.setOptions(setPanelOptions).then(() => { - console.log("Options set successfully using promise."); - }); + chrome.sidePanel.setOptions(setPanelOptions); // $ExpectType Promise + chrome.sidePanel.setOptions(setPanelOptions, () => void 0); // $ExpectType void + // @ts-expect-error + chrome.sidePanel.setOptions(setPanelOptions, () => {}).then(() => {}); - let setPanelBehavior: chrome.sidePanel.PanelBehavior = { + const setPanelBehavior: chrome.sidePanel.PanelBehavior = { openPanelOnActionClick: true, }; - chrome.sidePanel.setPanelBehavior(setPanelBehavior, () => { - console.log("Behavior set successfully using callback."); - }); - - chrome.sidePanel.setPanelBehavior(setPanelBehavior).then(() => { - console.log("Behavior set successfully using promise."); - }); + chrome.sidePanel.setPanelBehavior(setPanelBehavior); // $ExpectType Promise + chrome.sidePanel.setPanelBehavior(setPanelBehavior, () => void 0); // $ExpectType void + // @ts-expect-error + chrome.sidePanel.setPanelBehavior(setPanelBehavior, () => {}).then(() => {}); } // https://developer.chrome.com/docs/extensions/reference/api/instanceID From 0d72867889a2288747ab2a90764c831cff65d057 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 1 Oct 2025 15:30:44 -0400 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#73796=20Add=20?= =?UTF-8?q?@types/deno=202.5=20by=20@dsherret?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/deno/deno-tests.ts | 2 +- types/deno/index.d.ts | 744 +++++++++++++++++++++++++++++++-------- types/deno/package.json | 2 +- 3 files changed, 597 insertions(+), 151 deletions(-) diff --git a/types/deno/deno-tests.ts b/types/deno/deno-tests.ts index e1e9f103b730e3..03ca6f135c1839 100644 --- a/types/deno/deno-tests.ts +++ b/types/deno/deno-tests.ts @@ -7,4 +7,4 @@ Deno.mkdirSync("dir"); // $ExpectType void Deno.readTextFileSync("dir/file.txt"); // $ExpectType string Deno.readTextFileSync(new URL("./file.txt", import.meta.url)); // $ExpectType string new Deno.errors.NotFound(); // $ExpectType NotFound -Deno.jupyter.broadcast("type", { "data": 5 }); // $ExpectType Promise +Deno.jupyter.broadcast("type", { "data": 6 }); // $ExpectType Promise diff --git a/types/deno/index.d.ts b/types/deno/index.d.ts index 2680d4b1a75fc0..99bc5e7646213d 100644 --- a/types/deno/index.d.ts +++ b/types/deno/index.d.ts @@ -92,7 +92,7 @@ declare namespace Deno { * @category Errors */ export class AlreadyExists extends Error {} /** - * Raised when an operation to returns data that is invalid for the + * Raised when an operation returns data that is invalid for the * operation being performed. * * @category Errors */ @@ -106,7 +106,7 @@ declare namespace Deno { /** * Raised when the underlying operating system reports an `EINTR` error. In * many cases, this underlying IO error will be handled internally within - * Deno, or result in an @{link BadResource} error instead. + * Deno, or result in an {@link BadResource} error instead. * * @category Errors */ export class Interrupted extends Error {} @@ -1024,6 +1024,78 @@ declare namespace Deno { options: Omit, fn: (t: TestContext) => void | Promise, ): void; + + /** Register a function to be called before all tests in the current scope. + * + * These functions are run in FIFO order (first in, first out). + * + * If an exception is raised during execution of this hook, the remaining `beforeAll` hooks will not be run. + * + * ```ts + * Deno.test.beforeAll(() => { + * // Setup code that runs once before all tests + * console.log("Setting up test suite"); + * }); + * ``` + * + * @category Testing + */ + beforeAll( + fn: () => void | Promise, + ): void; + + /** Register a function to be called before each test in the current scope. + * + * These functions are run in FIFO order (first in, first out). + * + * If an exception is raised during execution of this hook, the remaining hooks will not be run and the currently running + * test case will be marked as failed. + * + * ```ts + * Deno.test.beforeEach(() => { + * // Setup code that runs before each test + * console.log("Setting up test"); + * }); + * ``` + * + * @category Testing + */ + beforeEach(fn: () => void | Promise): void; + + /** Register a function to be called after each test in the current scope. + * + * These functions are run in LIFO order (last in, first out). + * + * If an exception is raised during execution of this hook, the remaining hooks will not be run and the currently running + * test case will be marked as failed. + * + * ```ts + * Deno.test.afterEach(() => { + * // Cleanup code that runs after each test + * console.log("Cleaning up test"); + * }); + * ``` + * + * @category Testing + */ + afterEach(fn: () => void | Promise): void; + + /** Register a function to be called after all tests in the current scope have finished running. + * + * These functions are run in the LIFO order (last in, first out). + * + * If an exception is raised during execution of this hook, the remaining `afterAll` hooks will not be run. + * + * ```ts + * Deno.test.afterAll(() => { + * // Cleanup code that runs once after all tests + * console.log("Cleaning up test suite"); + * }); + * ``` + * + * @category Testing + */ + afterAll(fn: () => void | Promise): void; } /** @@ -1368,7 +1440,7 @@ declare namespace Deno { * * ```ts * console.log(Deno.env.get("HOME")); // e.g. outputs "/home/alice" - * console.log(Deno.env.get("MADE_UP_VAR")); // outputs "undefined" + * console.log(Deno.env.get("MADE_UP_VAR")); // outputs undefined * ``` * * Requires `allow-env` permission. @@ -1449,9 +1521,6 @@ declare namespace Deno { * console.log(Deno.execPath()); // e.g. "/home/alice/.local/bin/deno" * ``` * - * Requires `allow-read` permission. - * - * @tags allow-read * @category Runtime */ export function execPath(): string; @@ -2562,7 +2631,8 @@ declare namespace Deno { * | 1 | execute only | * | 0 | no permission | * - * NOTE: This API currently throws on Windows + * Note: On Windows, only the read and write permissions can be modified. + * Distinctions between owner, group, and others are not supported. * * Requires `allow-write` permission. * @@ -2580,8 +2650,6 @@ declare namespace Deno { * * For a full description, see {@linkcode Deno.chmod}. * - * NOTE: This API currently throws on Windows - * * Requires `allow-write` permission. * * @tags allow-write @@ -3300,24 +3368,6 @@ declare namespace Deno { */ export function truncateSync(name: string, len?: number): void; - /** @category Runtime - * - * @deprecated This will be removed in Deno 2.0. - */ - export interface OpMetrics { - opsDispatched: number; - opsDispatchedSync: number; - opsDispatchedAsync: number; - opsDispatchedAsyncUnref: number; - opsCompleted: number; - opsCompletedSync: number; - opsCompletedAsync: number; - opsCompletedAsyncUnref: number; - bytesSentControl: number; - bytesSentData: number; - bytesReceived: number; - } - /** * Additional information for FsEvent objects with the "other" kind. * @@ -3599,8 +3649,8 @@ declare namespace Deno { */ export class ChildProcess implements AsyncDisposable { get stdin(): WritableStream>; - get stdout(): ReadableStream>; - get stderr(): ReadableStream>; + get stdout(): SubprocessReadableStream; + get stderr(): SubprocessReadableStream; readonly pid: number; /** Get the status of the child. */ readonly status: Promise; @@ -3626,6 +3676,35 @@ declare namespace Deno { [Symbol.asyncDispose](): Promise; } + /** + * The interface for stdout and stderr streams for child process returned from + * {@linkcode Deno.Command.spawn}. + * + * @category Subprocess + */ + export interface SubprocessReadableStream extends ReadableStream> { + /** + * Reads the stream to completion. It returns a promise that resolves with + * an `ArrayBuffer`. + */ + arrayBuffer(): Promise; + /** + * Reads the stream to completion. It returns a promise that resolves with + * a `Uint8Array`. + */ + bytes(): Promise>; + /** + * Reads the stream to completion. It returns a promise that resolves with + * the result of parsing the body text as JSON. + */ + json(): Promise; + /** + * Reads the stream to completion. It returns a promise that resolves with + * a `USVString` (text). + */ + text(): Promise; + } + /** * Options which can be set when calling {@linkcode Deno.Command}. * @@ -3688,6 +3767,20 @@ declare namespace Deno { * * @default {false} */ windowsRawArguments?: boolean; + + /** Whether to detach the spawned process from the current process. + * This allows the spawned process to continue running after the current + * process exits. + * + * Note: In order to allow the current process to exit, you need to ensure + * you call `unref()` on the child process. + * + * In addition, the stdio streams – if inherited or piped – may keep the + * current process from exiting until the streams are closed. + * + * @default {false} + */ + detached?: boolean; } /** @@ -3948,6 +4041,21 @@ declare namespace Deno { path?: string | URL; } + /** The permission descriptor for the `allow-import` and `deny-import` permissions, which controls + * access to importing from remote hosts via the network. The option `host` allows scoping the + * permission for outbound connection to a specific host and port. + * + * @category Permissions */ + export interface ImportPermissionDescriptor { + name: "import"; + /** Optional host string of the form `"[:]"`. Examples: + * + * "github.com" + * "deno.land:8080" + */ + host?: string; + } + /** Permission descriptors which define a permission and can be queried, * requested, or revoked. * @@ -3963,7 +4071,8 @@ declare namespace Deno { | NetPermissionDescriptor | EnvPermissionDescriptor | SysPermissionDescriptor - | FfiPermissionDescriptor; + | FfiPermissionDescriptor + | ImportPermissionDescriptor; /** The interface which defines what event types are supported by * {@linkcode PermissionStatus} instances. @@ -4955,6 +5064,12 @@ declare namespace Deno { * @category HTTP Server */ fetch: ServeHandler; + /** + * The callback which is called when the server starts listening. + * + * @category HTTP Server + */ + onListen?: (localAddr: Deno.Addr) => void; } /** Options which can be set when calling {@linkcode Deno.serve}. @@ -5001,6 +5116,18 @@ declare namespace Deno { /** Sets `SO_REUSEPORT` on POSIX systems. */ reusePort?: boolean; + + /** Maximum number of pending connections in the listen queue. + * + * This parameter controls how many incoming connections can be queued by the + * operating system while waiting for the application to accept them. If more + * connections arrive when the queue is full, they will be refused. + * + * The kernel may adjust this value (e.g., rounding up to the next power of 2 + * plus 1). Different operating systems have different maximum limits. + * + * @default {511} */ + tcpBacklog?: number; } /** @@ -5522,7 +5649,7 @@ declare namespace Deno { * * @category FFI */ - export type FromNativeType = T extends NativeStructType ? Uint8Array + export type FromNativeType = T extends NativeStructType ? Uint8Array : T extends NativeNumberType ? T extends NativeU8Enum ? U : T extends NativeI8Enum ? U : T extends NativeU16Enum ? U @@ -5545,7 +5672,7 @@ declare namespace Deno { */ export type FromNativeResultType< T extends NativeResultType = NativeResultType, - > = T extends NativeStructType ? Uint8Array + > = T extends NativeStructType ? Uint8Array : T extends NativeNumberType ? T extends NativeU8Enum ? U : T extends NativeI8Enum ? U : T extends NativeU16Enum ? U @@ -6030,7 +6157,7 @@ declare namespace Deno { * * Must be in PEM format. */ caCerts?: string[]; - /** A HTTP proxy to use for new connections. */ + /** An alternative transport (a proxy) to use for new connections. */ proxy?: Proxy; /** Sets the maximum number of idle connections per host allowed in the pool. */ poolMaxIdlePerHost?: number; @@ -6058,17 +6185,53 @@ declare namespace Deno { } /** - * The definition of a proxy when specifying + * The definition for alternative transports (or proxies) in * {@linkcode Deno.CreateHttpClientOptions}. * + * Supported proxies: + * - HTTP/HTTPS proxy: this uses passthrough to tunnel HTTP requests, or HTTP + * CONNECT to tunnel HTTPS requests through a different server. + * - SOCKS5 proxy: this uses the SOCKS5 protocol to tunnel TCP connections + * through a different server. + * - TCP socket: this sends all requests to a specified TCP socket. + * - Unix domain socket: this sends all requests to a local Unix domain + * socket rather than a TCP socket. *Not supported on Windows.* + * - Vsock socket: this sends all requests to a local vsock socket. + * *Only supported on Linux and macOS.* + * * @category Fetch */ - export interface Proxy { - /** The string URL of the proxy server to use. */ + export type Proxy = { + transport?: "http" | "https" | "socks5"; + /** + * The string URL of the proxy server to use. + * + * For `http` and `https` transports, the URL must start with `http://` or + * `https://` respectively, or be a plain hostname. + * + * For `socks` transport, the URL must start with `socks5://` or + * `socks5h://`. + */ url: string; /** The basic auth credentials to be used against the proxy server. */ basicAuth?: BasicAuth; - } + } | { + transport: "tcp"; + /** The hostname of the TCP server to connect to. */ + hostname: string; + /** The port of the TCP server to connect to. */ + port: number; + } | { + transport: "unix"; + /** The path to the unix domain socket to use. */ + path: string; + } | { + transport: "vsock"; + /** The CID (Context Identifier) of the vsock to connect to. */ + cid: number; + /** The port of the vsock to connect to. */ + port: number; + }; /** * Basic authentication credentials to be used with a {@linkcode Deno.Proxy} @@ -6120,6 +6283,89 @@ declare namespace Deno { | (CreateHttpClientOptions & TlsCertifiedKeyPem), ): HttpClient; + /** + * APIs for working with the OpenTelemetry observability framework. Deno can + * export traces, metrics, and logs to OpenTelemetry compatible backends via + * the OTLP protocol. + * + * Deno automatically instruments the runtime with OpenTelemetry traces and + * metrics. This data is exported via OTLP to OpenTelemetry compatible + * backends. User logs from the `console` API are exported as OpenTelemetry + * logs via OTLP. + * + * User code can also create custom traces, metrics, and logs using the + * OpenTelemetry API. This is done using the official OpenTelemetry package + * for JavaScript: + * [`npm:@opentelemetry/api`](https://opentelemetry.io/docs/languages/js/). + * Deno integrates with this package to provide tracing, metrics, and trace + * context propagation between native Deno APIs (like `Deno.serve` or `fetch`) + * and custom user code. Deno automatically registers the providers with the + * OpenTelemetry API, so users can start creating custom traces, metrics, and + * logs without any additional setup. + * + * @example Using OpenTelemetry API to create custom traces + * ```ts,ignore + * import { trace } from "npm:@opentelemetry/api@1"; + * + * const tracer = trace.getTracer("example-tracer"); + * + * async function doWork() { + * return tracer.startActiveSpan("doWork", async (span) => { + * span.setAttribute("key", "value"); + * await new Promise((resolve) => setTimeout(resolve, 1000)); + * span.end(); + * }); + * } + * + * Deno.serve(async (req) => { + * await doWork(); + * const resp = await fetch("https://example.com"); + * return resp; + * }); + * ``` + * + * @category Telemetry + */ + export namespace telemetry { + /** + * A TracerProvider compatible with OpenTelemetry.js + * https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_api.TracerProvider.html + * + * This is a singleton object that implements the OpenTelemetry + * TracerProvider interface. + * + * @category Telemetry + */ + // deno-lint-ignore no-explicit-any + export const tracerProvider: any; + + /** + * A ContextManager compatible with OpenTelemetry.js + * https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_api.ContextManager.html + * + * This is a singleton object that implements the OpenTelemetry + * ContextManager interface. + * + * @category Telemetry + */ + // deno-lint-ignore no-explicit-any + export const contextManager: any; + + /** + * A MeterProvider compatible with OpenTelemetry.js + * https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_api.MeterProvider.html + * + * This is a singleton object that implements the OpenTelemetry + * MeterProvider interface. + * + * @category Telemetry + */ + // deno-lint-ignore no-explicit-any + export const meterProvider: any; + + export {}; // only export exports + } + export {}; // only export exports } @@ -6877,20 +7123,32 @@ interface GPUCompilationInfo { readonly messages: ReadonlyArray; } -/** @category GPU */ -declare class GPUPipelineError extends DOMException { - constructor(message?: string, options?: GPUPipelineErrorInit); - - readonly reason: GPUPipelineErrorReason; +/** + * The **`GPUPipelineError`** interface of the WebGPU API describes a pipeline failure. + * Available only in secure contexts. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/GPUPipelineError) + * @category GPU + */ +interface GPUPipelineError extends DOMException { + /** + * The **`reason`** read-only property of the GPUPipelineError interface defines the reason the pipeline creation failed in a machine-readable way. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/GPUPipelineError/reason) + */ + readonly reason: "validation" | "internal"; } /** @category GPU */ -interface GPUPipelineErrorInit { - reason: GPUPipelineErrorReason; -} +declare var GPUPipelineError: { + prototype: GPUPipelineError; + new(message: string, options: GPUPipelineErrorInit): GPUPipelineError; +}; /** @category GPU */ -type GPUPipelineErrorReason = "validation" | "internal"; +interface GPUPipelineErrorInit { + reason: "validation" | "internal"; +} /** * Represents a compiled shader module that can be used to create graphics or compute pipelines. @@ -7699,25 +7957,55 @@ interface GPUDeviceLostInfo { readonly message: string; } -/** @category GPU */ -declare class GPUError { +/** + * The **`GPUError`** interface of the WebGPU API is the base interface for errors surfaced by GPUDevice.popErrorScope and the GPUDevice.uncapturederror_event event. + * Available only in secure contexts. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/GPUError) + * @category GPU + */ +interface GPUError { + /** + * The **`message`** read-only property of the A string. + * The **`message`** read-only property of the GPUError interface provides a human-readable message that explains why the error occurred. + * + * [MDN Reference](https://developer.mozilla.org/docs/Web/API/GPUError/message) + */ readonly message: string; } /** @category GPU */ -declare class GPUOutOfMemoryError extends GPUError { - constructor(message: string); -} +declare var GPUError: { + prototype: GPUError; + new(): GPUError; +}; /** @category GPU */ -declare class GPUValidationError extends GPUError { - constructor(message: string); -} +interface GPUOutOfMemoryError extends GPUError {} /** @category GPU */ -declare class GPUInternalError extends GPUError { - constructor(message: string); -} +declare var GPUOutOfMemoryError: { + prototype: GPUOutOfMemoryError; + new(message?: string): GPUOutOfMemoryError; +}; + +/** @category GPU */ +interface GPUValidationError extends GPUError {} + +/** @category GPU */ +declare var GPUValidationError: { + prototype: GPUValidationError; + new(message?: string): GPUValidationError; +}; + +/** @category GPU */ +interface GPUInternalError extends GPUError {} + +/** @category GPU */ +declare var GPUInternalError: { + prototype: GPUInternalError; + new(message?: string): GPUInternalError; +}; /** @category GPU */ type GPUErrorFilter = "out-of-memory" | "validation" | "internal"; @@ -7974,6 +8262,18 @@ declare namespace Deno { * * @default {"0.0.0.0"} */ hostname?: string; + + /** Maximum number of pending connections in the listen queue. + * + * This parameter controls how many incoming connections can be queued by the + * operating system while waiting for the application to accept them. If more + * connections arrive when the queue is full, they will be refused. + * + * The kernel may adjust this value (e.g., rounding up to the next power of 2 + * plus 1). Different operating systems have different maximum limits. + * + * @default {511} */ + tcpBacklog?: number; } /** @category Network */ @@ -8239,6 +8539,15 @@ declare namespace Deno { * TLS handshake. */ alpnProtocols?: string[]; + /** If true, the certificate's common name or subject alternative names will not be + * checked against the hostname provided in the options. + * + * This disables hostname verification but still validates the certificate chain. + * Use with caution and only when connecting to known servers. + * + * @default {false} + */ + unsafelyDisableHostnameVerification?: boolean; } /** Establishes a secure connection over TLS (transport layer security) using @@ -8288,6 +8597,15 @@ declare namespace Deno { * TLS handshake. */ alpnProtocols?: string[]; + /** If true, the certificate's common name or subject alternative names will not be + * checked against the hostname provided in the options. + * + * This disables hostname verification but still validates the certificate chain. + * Use with caution and only when connecting to known servers. + * + * @default {false} + */ + unsafelyDisableHostnameVerification?: boolean; } /** Start TLS handshake from an existing connection using an optional list of @@ -8538,7 +8856,7 @@ declare namespace Deno { * @experimental * @category Network */ - export interface QuicListener extends AsyncIterable { + export interface QuicListener extends AsyncIterable { /** Waits for and resolves to the next incoming connection. */ incoming(): Promise; @@ -8548,7 +8866,7 @@ declare namespace Deno { /** Stops the listener. This does not close the endpoint. */ stop(): void; - [Symbol.asyncIterator](): AsyncIterableIterator; + [Symbol.asyncIterator](): AsyncIterableIterator; /** The endpoint for this listener. */ readonly endpoint: QuicEndpoint; @@ -8738,6 +9056,173 @@ declare namespace Deno { declare namespace Deno { export {}; // stop default export type behavior + /** + * @category Bundler + * @experimental + */ + export namespace bundle { + /** + * The target platform of the bundle. + * @category Bundler + * @experimental + */ + export type Platform = "browser" | "deno"; + + /** + * The output format of the bundle. + * @category Bundler + * @experimental + */ + export type Format = "esm" | "cjs" | "iife"; + + /** + * The source map type of the bundle. + * @category Bundler + * @experimental + */ + export type SourceMapType = "linked" | "inline" | "external"; + + /** + * How to handle packages. + * + * - `bundle`: packages are inlined into the bundle. + * - `external`: packages are excluded from the bundle, and treated as external dependencies. + * @category Bundler + * @experimental + */ + export type PackageHandling = "bundle" | "external"; + + /** + * Options for the bundle. + * @category Bundler + * @experimental + */ + export interface Options { + /** + * The entrypoints of the bundle. + */ + entrypoints: string[]; + /** + * Output file path. + */ + outputPath?: string; + /** + * Output directory path. + */ + outputDir?: string; + /** + * External modules to exclude from bundling. + */ + external?: string[]; + /** + * Bundle format. + */ + format?: Format; + /** + * Whether to minify the output. + */ + minify?: boolean; + /** + * Whether to enable code splitting. + */ + codeSplitting?: boolean; + /** + * Whether to inline imports. + */ + inlineImports?: boolean; + /** + * How to handle packages. + */ + packages?: PackageHandling; + /** + * Source map configuration. + */ + sourcemap?: SourceMapType; + /** + * Target platform. + */ + platform?: Platform; + + /** + * Whether to write the output to the filesystem. + * + * @default true if outputDir or outputPath is set, false otherwise + */ + write?: boolean; + } + + /** + * The location of a message. + * @category Bundler + * @experimental + */ + export interface MessageLocation { + file: string; + namespace?: string; + line: number; + column: number; + length: number; + suggestion?: string; + } + + /** + * A note about a message. + * @category Bundler + * @experimental + */ + export interface MessageNote { + text: string; + location?: MessageLocation; + } + + /** + * A message emitted from the bundler. + * @category Bundler + * @experimental + */ + export interface Message { + text: string; + location?: MessageLocation; + notes?: MessageNote[]; + } + + /** + * An output file in the bundle. + * @category Bundler + * @experimental + */ + export interface OutputFile { + path: string; + contents?: Uint8Array; + hash: string; + text(): string; + } + + /** + * The result of bundling. + * @category Bundler + * @experimental + */ + export interface Result { + errors: Message[]; + warnings: Message[]; + success: boolean; + outputFiles?: OutputFile[]; + } + + export {}; // only export exports + } + + /** **UNSTABLE**: New API, yet to be vetted. + * + * Bundle Typescript/Javascript code + * @category Bundle + * @experimental + */ + export function bundle( + options: Deno.bundle.Options, + ): Promise; + /** **UNSTABLE**: New API, yet to be vetted. * * Creates a presentable WebGPU surface from given window and @@ -8767,6 +9252,10 @@ declare namespace Deno { ); getContext(context: "webgpu"): GPUCanvasContext; present(): void; + /** + * This method should be invoked when the size of the window changes. + */ + resize(width: number, height: number): void; } /** **UNSTABLE**: New API, yet to be vetted. @@ -9983,95 +10472,6 @@ declare namespace Deno { export {}; // only export exports } - /** - * **UNSTABLE**: New API, yet to be vetted. - * - * APIs for working with the OpenTelemetry observability framework. Deno can - * export traces, metrics, and logs to OpenTelemetry compatible backends via - * the OTLP protocol. - * - * Deno automatically instruments the runtime with OpenTelemetry traces and - * metrics. This data is exported via OTLP to OpenTelemetry compatible - * backends. User logs from the `console` API are exported as OpenTelemetry - * logs via OTLP. - * - * User code can also create custom traces, metrics, and logs using the - * OpenTelemetry API. This is done using the official OpenTelemetry package - * for JavaScript: - * [`npm:@opentelemetry/api`](https://opentelemetry.io/docs/languages/js/). - * Deno integrates with this package to provide tracing, metrics, and trace - * context propagation between native Deno APIs (like `Deno.serve` or `fetch`) - * and custom user code. Deno automatically registers the providers with the - * OpenTelemetry API, so users can start creating custom traces, metrics, and - * logs without any additional setup. - * - * @example Using OpenTelemetry API to create custom traces - * ```ts,ignore - * import { trace } from "npm:@opentelemetry/api@1"; - * - * const tracer = trace.getTracer("example-tracer"); - * - * async function doWork() { - * return tracer.startActiveSpan("doWork", async (span) => { - * span.setAttribute("key", "value"); - * await new Promise((resolve) => setTimeout(resolve, 1000)); - * span.end(); - * }); - * } - * - * Deno.serve(async (req) => { - * await doWork(); - * const resp = await fetch("https://example.com"); - * return resp; - * }); - * ``` - * - * @category Telemetry - * @experimental - */ - export namespace telemetry { - /** - * A TracerProvider compatible with OpenTelemetry.js - * https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_api.TracerProvider.html - * - * This is a singleton object that implements the OpenTelemetry - * TracerProvider interface. - * - * @category Telemetry - * @experimental - */ - // deno-lint-ignore no-explicit-any - export const tracerProvider: any; - - /** - * A ContextManager compatible with OpenTelemetry.js - * https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_api.ContextManager.html - * - * This is a singleton object that implements the OpenTelemetry - * ContextManager interface. - * - * @category Telemetry - * @experimental - */ - // deno-lint-ignore no-explicit-any - export const contextManager: any; - - /** - * A MeterProvider compatible with OpenTelemetry.js - * https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_api.MeterProvider.html - * - * This is a singleton object that implements the OpenTelemetry - * MeterProvider interface. - * - * @category Telemetry - * @experimental - */ - // deno-lint-ignore no-explicit-any - export const meterProvider: any; - - export {}; // only export exports - } - /** * @category Linter * @experimental @@ -10134,6 +10534,27 @@ declare namespace Deno { * current node. */ getAncestors(node: Node): Node[]; + + /** + * Get all comments inside the source. + */ + getAllComments(): Array; + + /** + * Get leading comments before a node. + */ + getCommentsBefore(node: Node): Array; + + /** + * Get trailing comments after a node. + */ + getCommentsAfter(node: Node): Array; + + /** + * Get comments inside a node. + */ + getCommentsInside(node: Node): Array; + /** * Get the full source code. */ @@ -10260,6 +10681,7 @@ declare namespace Deno { range: Range; sourceType: "module" | "script"; body: Statement[]; + comments: Array; } /** @@ -13063,6 +13485,28 @@ declare namespace Deno { | TSUnknownKeyword | TSVoidKeyword; + /** + * A single line comment + * @category Linter + * @experimental + */ + export interface LineComment { + type: "Line"; + range: Range; + value: string; + } + + /** + * A potentially multi-line block comment + * @category Linter + * @experimental + */ + export interface BlockComment { + type: "Block"; + range: Range; + value: string; + } + /** * Union type of all possible AST nodes * @category Linter @@ -13122,7 +13566,9 @@ declare namespace Deno { | TSIndexSignature | TSTypeAnnotation | TSTypeParameterDeclaration - | TSTypeParameter; + | TSTypeParameter + | LineComment + | BlockComment; export {}; // only export exports } diff --git a/types/deno/package.json b/types/deno/package.json index b148ad0ddfbea2..560c19a8b2ff6d 100644 --- a/types/deno/package.json +++ b/types/deno/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@types/deno", - "version": "2.3.9999", + "version": "2.5.9999", "type": "module", "minimumTypeScriptVersion": "5.7", "nonNpm": "conflict", From a8df5b8f1fd8af8c92e27f89c4c02f19ef4ca286 Mon Sep 17 00:00:00 2001 From: "Sebastian \"Sebbie\" Silbermann" Date: Wed, 1 Oct 2025 23:49:09 +0200 Subject: [PATCH 4/4] [react] 19.2 (#73789) --- types/react-dom/canary.d.ts | 70 ------------------------ types/react-dom/index.d.ts | 5 ++ types/react-dom/package.json | 4 +- types/react-dom/server.d.ts | 23 ++++++++ types/react-dom/server.edge.d.ts | 2 +- types/react-dom/server.node.d.ts | 9 ++- types/react-dom/static.d.ts | 41 +++++++++++++- types/react-dom/static.edge.d.ts | 2 +- types/react-dom/static.node.d.ts | 8 ++- types/react-dom/test/canary-tests.tsx | 42 -------------- types/react-dom/test/react-dom-tests.tsx | 51 +++++++++++++---- types/react-is/package.json | 2 +- types/react/canary.d.ts | 31 ----------- types/react/index.d.ts | 35 ++++++++++++ types/react/package.json | 2 +- types/react/test/canary.tsx | 59 -------------------- types/react/test/hooks.tsx | 29 ++++++++++ types/react/test/index.ts | 12 ++++ types/react/test/tsx.tsx | 17 ++++++ types/react/ts5.0/canary.d.ts | 31 ----------- types/react/ts5.0/index.d.ts | 35 ++++++++++++ types/react/ts5.0/test/canary.tsx | 59 -------------------- types/react/ts5.0/test/hooks.tsx | 29 ++++++++++ types/react/ts5.0/test/index.ts | 12 ++++ types/react/ts5.0/test/tsx.tsx | 17 ++++++ 25 files changed, 315 insertions(+), 312 deletions(-) diff --git a/types/react-dom/canary.d.ts b/types/react-dom/canary.d.ts index 363a6aec669543..e0929224b20c79 100644 --- a/types/react-dom/canary.d.ts +++ b/types/react-dom/canary.d.ts @@ -32,73 +32,3 @@ import React = require("react"); import ReactDOM = require("."); export {}; - -declare module "react" { - // eslint-disable-next-line @typescript-eslint/no-empty-interface - interface CacheSignal extends AbortSignal {} -} - -declare const POSTPONED_STATE_SIGIL: unique symbol; -declare module "react-dom/static" { - /** - * This is an opaque type i.e. users should not make any assumptions about its structure. - * It is JSON-serializeable to be a able to store it and retrvieve later for use with {@link https://react.dev/reference/react-dom/server/resume `resume`}. - */ - interface PostponedState { - [POSTPONED_STATE_SIGIL]: never; - } - - interface ResumeOptions { - nonce?: string; - signal?: AbortSignal; - onError?: (error: unknown) => string | undefined | void; - } - - interface PrerenderResult { - postponed: null | PostponedState; - } - /** - * @see {@link https://react.dev/reference/react-dom/static/resumeAndPrerender `resumeAndPrerender` reference documentation} - * @version 19.2 - */ - function resumeAndPrerender( - children: React.ReactNode, - postponedState: PostponedState, - options?: Omit, - ): Promise; - - interface PrerenderToNodeStreamResult { - postponed: null | PostponedState; - } - /** - * @see {@link https://react.dev/reference/react-dom/static/resumeAndPrerenderToNodeStream `resumeAndPrerenderToNodeStream`` reference documentation} - * @version 19.2 - */ - function resumeAndPrerenderToNodeStream( - children: React.ReactNode, - postponedState: PostponedState, - options?: Omit, - ): Promise; -} - -import { PostponedState, ResumeOptions } from "react-dom/static"; -declare module "react-dom/server" { - /** - * @see {@link https://react.dev/reference/react-dom/server/resume `resume`` reference documentation} - * @version 19.2 - */ - function resume( - children: React.ReactNode, - postponedState: PostponedState, - options?: ResumeOptions, - ): Promise; - /** - * @see {@link https://react.dev/reference/react-dom/server/resumeToPipeableStream `resumeToPipeableStream`` reference documentation} - * @version 19.2 - */ - function resumeToPipeableStream( - children: React.ReactNode, - postponedState: PostponedState, - options?: ResumeOptions, - ): Promise; -} diff --git a/types/react-dom/index.d.ts b/types/react-dom/index.d.ts index 76efddd2215455..efb52b2747aa26 100644 --- a/types/react-dom/index.d.ts +++ b/types/react-dom/index.d.ts @@ -6,6 +6,11 @@ export as namespace ReactDOM; import { Key, ReactNode, ReactPortal } from "react"; +declare module "react" { + // eslint-disable-next-line @typescript-eslint/no-empty-interface + interface CacheSignal extends AbortSignal {} +} + export function createPortal( children: ReactNode, container: Element | DocumentFragment, diff --git a/types/react-dom/package.json b/types/react-dom/package.json index 8f1419e4a345cc..713aebd50464a0 100644 --- a/types/react-dom/package.json +++ b/types/react-dom/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@types/react-dom", - "version": "19.1.9999", + "version": "19.2.9999", "projects": [ "https://react.dev/" ], @@ -78,7 +78,7 @@ } }, "peerDependencies": { - "@types/react": "^19.0.0" + "@types/react": "^19.2.0" }, "devDependencies": { "@types/react-dom": "workspace:." diff --git a/types/react-dom/server.d.ts b/types/react-dom/server.d.ts index f5fac9a041d13e..f07bd68f334f8b 100644 --- a/types/react-dom/server.d.ts +++ b/types/react-dom/server.d.ts @@ -23,6 +23,7 @@ declare global { import { ReactNode } from "react"; import { ErrorInfo, ReactFormState } from "./client"; +import { PostponedState, ResumeOptions } from "./static"; export interface BootstrapScriptDescriptor { src: string; @@ -155,6 +156,28 @@ export function renderToReadableStream( options?: RenderToReadableStreamOptions, ): Promise; +export { ResumeOptions }; + +/** + * @see {@link https://react.dev/reference/react-dom/server/resume `resume`` reference documentation} + * @version 19.2 + */ +export function resume( + children: React.ReactNode, + postponedState: PostponedState, + options?: ResumeOptions, +): Promise; + +/** + * @see {@link https://react.dev/reference/react-dom/server/resumeToPipeableStream `resumeToPipeableStream`` reference documentation} + * @version 19.2 + */ +export function resumeToPipeableStream( + children: React.ReactNode, + postponedState: PostponedState, + options?: ResumeOptions, +): Promise; + export const version: string; export as namespace ReactDOMServer; diff --git a/types/react-dom/server.edge.d.ts b/types/react-dom/server.edge.d.ts index f2e3bc930b3298..f21d7d2b5ef229 100644 --- a/types/react-dom/server.edge.d.ts +++ b/types/react-dom/server.edge.d.ts @@ -1 +1 @@ -export { renderToReadableStream, renderToStaticMarkup, renderToString } from "./server"; +export { renderToReadableStream, renderToStaticMarkup, renderToString, resume } from "./server"; diff --git a/types/react-dom/server.node.d.ts b/types/react-dom/server.node.d.ts index 5f426f2a6280f6..eb777a990353d8 100644 --- a/types/react-dom/server.node.d.ts +++ b/types/react-dom/server.node.d.ts @@ -1 +1,8 @@ -export { renderToPipeableStream, renderToStaticMarkup, renderToString } from "./server"; +export { + renderToPipeableStream, + renderToReadableStream, + renderToStaticMarkup, + renderToString, + resume, + resumeToPipeableStream, +} from "./server"; diff --git a/types/react-dom/static.d.ts b/types/react-dom/static.d.ts index 4a42b58a1d09b8..c86d5c10e6728c 100644 --- a/types/react-dom/static.d.ts +++ b/types/react-dom/static.d.ts @@ -26,6 +26,17 @@ declare global { import { ReactNode } from "react"; import { ErrorInfo } from "./client"; +export {}; + +declare const POSTPONED_STATE_SIGIL: unique symbol; + +/** + * This is an opaque type i.e. users should not make any assumptions about its structure. + * It is JSON-serializeable to be a able to store it and retrvieve later for use with {@link https://react.dev/reference/react-dom/server/resume `resume`}. + */ +export interface PostponedState { + [POSTPONED_STATE_SIGIL]: never; +} /** * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap Import maps} @@ -72,7 +83,7 @@ export interface PrerenderOptions { */ headersLengthHint?: number | undefined; identifierPrefix?: string; - importMap?: ImportMap | undefined; + importMap?: ReactImportMap | undefined; namespaceURI?: string; onError?: (error: unknown, errorInfo: ErrorInfo) => string | void; onHeaders?: (headers: Headers) => void | undefined; @@ -81,6 +92,7 @@ export interface PrerenderOptions { } export interface PrerenderResult { + postponed: null | PostponedState; prelude: ReadableStream; } @@ -96,6 +108,7 @@ export function prerender( export interface PrerenderToNodeStreamResult { prelude: NodeJS.ReadableStream; + postponed: null | PostponedState; } /** @@ -111,4 +124,30 @@ export function prerenderToNodeStream( options?: PrerenderOptions, ): Promise; +export interface ResumeOptions { + nonce?: string; + signal?: AbortSignal; + onError?: (error: unknown) => string | undefined | void; +} + +/** + * @see {@link https://react.dev/reference/react-dom/static/resumeAndPrerender `resumeAndPrerender` reference documentation} + * @version 19.2 + */ +export function resumeAndPrerender( + children: React.ReactNode, + postponedState: null | PostponedState, + options?: Omit, +): Promise; + +/** + * @see {@link https://react.dev/reference/react-dom/static/resumeAndPrerenderToNodeStream `resumeAndPrerenderToNodeStream`` reference documentation} + * @version 19.2 + */ +export function resumeAndPrerenderToNodeStream( + children: React.ReactNode, + postponedState: null | PostponedState, + options?: Omit, +): Promise; + export const version: string; diff --git a/types/react-dom/static.edge.d.ts b/types/react-dom/static.edge.d.ts index cd2d05ff521081..94c5393729fd34 100644 --- a/types/react-dom/static.edge.d.ts +++ b/types/react-dom/static.edge.d.ts @@ -1 +1 @@ -export { prerender, version } from "./static"; +export { prerender, resumeAndPrerender, version } from "./static"; diff --git a/types/react-dom/static.node.d.ts b/types/react-dom/static.node.d.ts index cb7017ebfa0ee1..59dd5ddddbd7f6 100644 --- a/types/react-dom/static.node.d.ts +++ b/types/react-dom/static.node.d.ts @@ -1 +1,7 @@ -export { prerenderToNodeStream, version } from "./static"; +export { + prerender, + prerenderToNodeStream, + resumeAndPrerender, + resumeAndPrerenderToNodeStream, + version, +} from "./static"; diff --git a/types/react-dom/test/canary-tests.tsx b/types/react-dom/test/canary-tests.tsx index 6a226d9c29acb1..d7857c7449e1c2 100644 --- a/types/react-dom/test/canary-tests.tsx +++ b/types/react-dom/test/canary-tests.tsx @@ -4,45 +4,3 @@ import ReactDOM = require("react-dom"); import ReactDOMClient = require("react-dom/client"); import ReactDOMServer = require("react-dom/server"); import ReactDOMStatic = require("react-dom/static"); - -function cacheSignalTest() { - const cacheSignal = React.cacheSignal; - - const signal = cacheSignal(); - if (signal !== null) { - // $ExpectType CacheSignal - signal; - if (signal.aborted) { - console.error(signal.reason); - } - } -} - -async function resumeTest(children: React.ReactNode) { - const prerenderController = new AbortController(); - setTimeout(prerenderController.abort, 1); - const { prelude, postponed } = await ReactDOMStatic.prerender(children, { signal: prerenderController.signal }); - - let stream: ReadableStream; - if (postponed !== null) { - const resumeController = new AbortController(); - const reactStream = await ReactDOMServer.resume(children, postponed, { - nonce: "nonce", - signal: resumeController.signal, - onError(error) { - return (error as { digest?: string | undefined }).digest; - }, - }); - await reactStream.allReady; - // In a real app you'd also have to flush the prelude first - stream = reactStream; - } else { - stream = prelude; - } - - await ReactDOMServer.resume( - children, - // @ts-expect-error Requires the opaque postponed state - {}, - ); -} diff --git a/types/react-dom/test/react-dom-tests.tsx b/types/react-dom/test/react-dom-tests.tsx index c45b6b401f91c2..296d25128ed5e4 100644 --- a/types/react-dom/test/react-dom-tests.tsx +++ b/types/react-dom/test/react-dom-tests.tsx @@ -72,19 +72,35 @@ describe("ReactDOMServer", () => { }); }); +declare const children: React.ReactNode; describe("ReactDOMStatic", () => { it("prerender", async () => { - const prelude: ReadableStream = - (await ReactDOMStatic.prerender(React.createElement("div"))).prelude; - ReactDOMStatic.prerender(React.createElement("div"), { - bootstrapScripts: ["./my-script.js"], - headersLengthHint: 4000, - importMap, - onHeaders(headers) { - // $ExpectType Headers - headers; - }, - }); + const prerenderController = new AbortController(); + setTimeout(prerenderController.abort, 1); + const { prelude, postponed } = await ReactDOMStatic.prerender(children, { signal: prerenderController.signal }); + + let stream: ReadableStream; + if (postponed !== null) { + const resumeController = new AbortController(); + const reactStream = await ReactDOMServer.resume(children, postponed, { + nonce: "nonce", + signal: resumeController.signal, + onError(error) { + return (error as { digest?: string | undefined }).digest; + }, + }); + await reactStream.allReady; + // In a real app you'd also have to flush the prelude first + stream = reactStream; + } else { + stream = prelude; + } + + await ReactDOMServer.resume( + children, + // @ts-expect-error Requires the opaque postponed state + {}, + ); }); it("prerenderToNodeStream", async () => { @@ -671,3 +687,16 @@ function requestFormResetTest(form: HTMLFormElement, button: HTMLButtonElement) // @ts-expect-error ReactDOM.requestFormReset(null); } + +function cacheSignalTest() { + const cacheSignal = React.cacheSignal; + + const signal = cacheSignal(); + if (signal !== null) { + // $ExpectType CacheSignal + signal; + if (signal.aborted) { + console.error(signal.reason); + } + } +} diff --git a/types/react-is/package.json b/types/react-is/package.json index c1a64dad57f5f0..e4f81c163bab1e 100644 --- a/types/react-is/package.json +++ b/types/react-is/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@types/react-is", - "version": "19.0.9999", + "version": "19.2.9999", "projects": [ "https://reactjs.org/" ], diff --git a/types/react/canary.d.ts b/types/react/canary.d.ts index 9b7a5629b11b33..9215a16bb87bab 100644 --- a/types/react/canary.d.ts +++ b/types/react/canary.d.ts @@ -32,35 +32,4 @@ type VoidOrUndefinedOnly = void | { [UNDEFINED_VOID_ONLY]: never }; declare module "." { export function unstable_useCacheRefresh(): () => void; - - export interface CacheSignal {} - export function cacheSignal(): null | CacheSignal; - - // @enableActivity - export interface ActivityProps { - /** - * @default "visible" - */ - mode?: - | "hidden" - | "visible" - | undefined; - /** - * A name for this Activity boundary for instrumentation purposes. - * The name will help identify this boundary in React DevTools. - */ - name?: string | undefined; - children: ReactNode; - } - - /** - * @see {@link https://react.dev/reference/react/Activity `` documentation} - */ - export const Activity: ExoticComponent; - - /** - * @see {@link https://react.dev/reference/react/useEffectEvent `useEffectEvent()` documentation} - */ - // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type - export function useEffectEvent(callback: T): T; } diff --git a/types/react/index.d.ts b/types/react/index.d.ts index 788ad15b563819..5d82891b4a1bc0 100644 --- a/types/react/index.d.ts +++ b/types/react/index.d.ts @@ -1774,6 +1774,12 @@ declare namespace React { * @see {@link https://react.dev/reference/react/useEffect} */ function useEffect(effect: EffectCallback, deps?: DependencyList): void; + /** + * @see {@link https://react.dev/reference/react/useEffectEvent `useEffectEvent()` documentation} + * @version 19.2.0 + */ + // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type + export function useEffectEvent(callback: T): T; // NOTE: this does not accept strings, but this will have to be fixed by removing strings from type Ref /** * `useImperativeHandle` customizes the instance value that is exposed to parent components when using @@ -1938,10 +1944,39 @@ declare namespace React { // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type export function cache(fn: CachedFunction): CachedFunction; + export interface CacheSignal {} + /** + * @version 19.2.0 + */ + export function cacheSignal(): null | CacheSignal; + + export interface ActivityProps { + /** + * @default "visible" + */ + mode?: + | "hidden" + | "visible" + | undefined; + /** + * A name for this Activity boundary for instrumentation purposes. + * The name will help identify this boundary in React DevTools. + */ + name?: string | undefined; + children: ReactNode; + } + + /** + * @see {@link https://react.dev/reference/react/Activity `` documentation} + * @version 19.2.0 + */ + export const Activity: ExoticComponent; + /** * Warning: Only available in development builds. * * @see {@link https://react.dev/reference/react/captureOwnerStack Reference docs} + * @version 19.1.0 */ function captureOwnerStack(): string | null; diff --git a/types/react/package.json b/types/react/package.json index f168618d27556f..62e4079ee6075b 100644 --- a/types/react/package.json +++ b/types/react/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@types/react", - "version": "19.1.9999", + "version": "19.2.9999", "projects": [ "https://react.dev/" ], diff --git a/types/react/test/canary.tsx b/types/react/test/canary.tsx index d3035d61f59474..117711db251c7e 100644 --- a/types/react/test/canary.tsx +++ b/types/react/test/canary.tsx @@ -25,62 +25,3 @@ function useCacheTest() { refresh(() => "refresh"); } } - -function cacheSignalTest() { - const cacheSignal = React.cacheSignal; - - const signal = cacheSignal(); - if (signal !== null) { - // $ExpectType CacheSignal - signal; - // @ts-expect-error -- implemented by renderer - signal.aborted; - } -} - -// @enableActivity -function activityTest() { - const Activity = React.Activity; - - ; - ; - ; - ; - // @ts-expect-error -- Forgot children - ; - ; - ; -} - -function useEffectEventTest() { - // Implicit any - // @ts-expect-error - const anyEvent = React.useEffectEvent(value => { - // $ExpectType any - return value; - }); - // $ExpectType any - anyEvent({}); - // $ExpectType (value: string) => number - const typedEvent = React.useEffectEvent((value: string) => { - return Number(value); - }); - // $ExpectType number - typedEvent("1"); - // Argument of type '{}' is not assignable to parameter of type 'string'. - // @ts-expect-error - typedEvent({}); - - function useContextuallyTypedEvent(fn: (event: Event) => string) {} - useContextuallyTypedEvent( - React.useEffectEvent(event => { - // $ExpectType Event - event; - return String(event); - }), - ); -} diff --git a/types/react/test/hooks.tsx b/types/react/test/hooks.tsx index 2ae9d9470673ac..852c5b81839c44 100644 --- a/types/react/test/hooks.tsx +++ b/types/react/test/hooks.tsx @@ -673,3 +673,32 @@ function formTest() { ); } } + +function useEffectEventTest() { + // Implicit any + // @ts-expect-error + const anyEvent = React.useEffectEvent(value => { + // $ExpectType any + return value; + }); + // $ExpectType any + anyEvent({}); + // $ExpectType (value: string) => number + const typedEvent = React.useEffectEvent((value: string) => { + return Number(value); + }); + // $ExpectType number + typedEvent("1"); + // Argument of type '{}' is not assignable to parameter of type 'string'. + // @ts-expect-error + typedEvent({}); + + function useContextuallyTypedEvent(fn: (event: Event) => string) {} + useContextuallyTypedEvent( + React.useEffectEvent(event => { + // $ExpectType Event + event; + return String(event); + }), + ); +} diff --git a/types/react/test/index.ts b/types/react/test/index.ts index c5d26106181c92..e273ddd4d3af4e 100644 --- a/types/react/test/index.ts +++ b/types/react/test/index.ts @@ -1033,3 +1033,15 @@ function ownerStacks() { // $ExpectType string | null const ownerStack = React.captureOwnerStack(); } + +function cacheSignalTest() { + const cacheSignal = React.cacheSignal; + + const signal = cacheSignal(); + if (signal !== null) { + // $ExpectType CacheSignal + signal; + // @ts-expect-error -- implemented by renderer + signal.aborted; + } +} diff --git a/types/react/test/tsx.tsx b/types/react/test/tsx.tsx index e2f06f152e85c8..58db3f3a1bab37 100644 --- a/types/react/test/tsx.tsx +++ b/types/react/test/tsx.tsx @@ -894,3 +894,20 @@ function managingRefs() { }} />; } + +function activityTest() { + const Activity = React.Activity; + + ; + ; + ; + ; + // @ts-expect-error -- Forgot children + ; + ; + ; +} diff --git a/types/react/ts5.0/canary.d.ts b/types/react/ts5.0/canary.d.ts index 9b7a5629b11b33..9215a16bb87bab 100644 --- a/types/react/ts5.0/canary.d.ts +++ b/types/react/ts5.0/canary.d.ts @@ -32,35 +32,4 @@ type VoidOrUndefinedOnly = void | { [UNDEFINED_VOID_ONLY]: never }; declare module "." { export function unstable_useCacheRefresh(): () => void; - - export interface CacheSignal {} - export function cacheSignal(): null | CacheSignal; - - // @enableActivity - export interface ActivityProps { - /** - * @default "visible" - */ - mode?: - | "hidden" - | "visible" - | undefined; - /** - * A name for this Activity boundary for instrumentation purposes. - * The name will help identify this boundary in React DevTools. - */ - name?: string | undefined; - children: ReactNode; - } - - /** - * @see {@link https://react.dev/reference/react/Activity `` documentation} - */ - export const Activity: ExoticComponent; - - /** - * @see {@link https://react.dev/reference/react/useEffectEvent `useEffectEvent()` documentation} - */ - // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type - export function useEffectEvent(callback: T): T; } diff --git a/types/react/ts5.0/index.d.ts b/types/react/ts5.0/index.d.ts index 02a1f914f434e0..3c2305eb280520 100644 --- a/types/react/ts5.0/index.d.ts +++ b/types/react/ts5.0/index.d.ts @@ -1773,6 +1773,12 @@ declare namespace React { * @see {@link https://react.dev/reference/react/useEffect} */ function useEffect(effect: EffectCallback, deps?: DependencyList): void; + /** + * @see {@link https://react.dev/reference/react/useEffectEvent `useEffectEvent()` documentation} + * @version 19.2.0 + */ + // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type + export function useEffectEvent(callback: T): T; // NOTE: this does not accept strings, but this will have to be fixed by removing strings from type Ref /** * `useImperativeHandle` customizes the instance value that is exposed to parent components when using @@ -1937,10 +1943,39 @@ declare namespace React { // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type export function cache(fn: CachedFunction): CachedFunction; + export interface CacheSignal {} + /** + * @version 19.2.0 + */ + export function cacheSignal(): null | CacheSignal; + + export interface ActivityProps { + /** + * @default "visible" + */ + mode?: + | "hidden" + | "visible" + | undefined; + /** + * A name for this Activity boundary for instrumentation purposes. + * The name will help identify this boundary in React DevTools. + */ + name?: string | undefined; + children: ReactNode; + } + + /** + * @see {@link https://react.dev/reference/react/Activity `` documentation} + * @version 19.2.0 + */ + export const Activity: ExoticComponent; + /** * Warning: Only available in development builds. * * @see {@link https://react.dev/reference/react/captureOwnerStack Reference docs} + * @version 19.1.0 */ function captureOwnerStack(): string | null; diff --git a/types/react/ts5.0/test/canary.tsx b/types/react/ts5.0/test/canary.tsx index d3035d61f59474..117711db251c7e 100644 --- a/types/react/ts5.0/test/canary.tsx +++ b/types/react/ts5.0/test/canary.tsx @@ -25,62 +25,3 @@ function useCacheTest() { refresh(() => "refresh"); } } - -function cacheSignalTest() { - const cacheSignal = React.cacheSignal; - - const signal = cacheSignal(); - if (signal !== null) { - // $ExpectType CacheSignal - signal; - // @ts-expect-error -- implemented by renderer - signal.aborted; - } -} - -// @enableActivity -function activityTest() { - const Activity = React.Activity; - - ; - ; - ; - ; - // @ts-expect-error -- Forgot children - ; - ; - ; -} - -function useEffectEventTest() { - // Implicit any - // @ts-expect-error - const anyEvent = React.useEffectEvent(value => { - // $ExpectType any - return value; - }); - // $ExpectType any - anyEvent({}); - // $ExpectType (value: string) => number - const typedEvent = React.useEffectEvent((value: string) => { - return Number(value); - }); - // $ExpectType number - typedEvent("1"); - // Argument of type '{}' is not assignable to parameter of type 'string'. - // @ts-expect-error - typedEvent({}); - - function useContextuallyTypedEvent(fn: (event: Event) => string) {} - useContextuallyTypedEvent( - React.useEffectEvent(event => { - // $ExpectType Event - event; - return String(event); - }), - ); -} diff --git a/types/react/ts5.0/test/hooks.tsx b/types/react/ts5.0/test/hooks.tsx index 2ae9d9470673ac..852c5b81839c44 100644 --- a/types/react/ts5.0/test/hooks.tsx +++ b/types/react/ts5.0/test/hooks.tsx @@ -673,3 +673,32 @@ function formTest() { ); } } + +function useEffectEventTest() { + // Implicit any + // @ts-expect-error + const anyEvent = React.useEffectEvent(value => { + // $ExpectType any + return value; + }); + // $ExpectType any + anyEvent({}); + // $ExpectType (value: string) => number + const typedEvent = React.useEffectEvent((value: string) => { + return Number(value); + }); + // $ExpectType number + typedEvent("1"); + // Argument of type '{}' is not assignable to parameter of type 'string'. + // @ts-expect-error + typedEvent({}); + + function useContextuallyTypedEvent(fn: (event: Event) => string) {} + useContextuallyTypedEvent( + React.useEffectEvent(event => { + // $ExpectType Event + event; + return String(event); + }), + ); +} diff --git a/types/react/ts5.0/test/index.ts b/types/react/ts5.0/test/index.ts index 8f9db917cfa528..d8b4cbd915d3dc 100644 --- a/types/react/ts5.0/test/index.ts +++ b/types/react/ts5.0/test/index.ts @@ -1036,3 +1036,15 @@ function ownerStacks() { // $ExpectType string | null const ownerStack = React.captureOwnerStack(); } + +function cacheSignalTest() { + const cacheSignal = React.cacheSignal; + + const signal = cacheSignal(); + if (signal !== null) { + // $ExpectType CacheSignal + signal; + // @ts-expect-error -- implemented by renderer + signal.aborted; + } +} diff --git a/types/react/ts5.0/test/tsx.tsx b/types/react/ts5.0/test/tsx.tsx index 3a55a0c89535b8..28be7ca67c4159 100644 --- a/types/react/ts5.0/test/tsx.tsx +++ b/types/react/ts5.0/test/tsx.tsx @@ -898,3 +898,20 @@ function managingRefs() { }} />; } + +function activityTest() { + const Activity = React.Activity; + + ; + ; + ; + ; + // @ts-expect-error -- Forgot children + ; + ; + ; +}