Repository: denoland/deno
Pull request: fix(dts): update some GPU types to not cause errors in upcoming DOM type declarations

See https://github.com/microsoft/TypeScript/pull/62496#issuecomment-3340761035

Changed files:
filename: cli/tsc/dts/lib.deno.unstable.d.ts
patch: @@ -162,6 +162,8 @@ declare namespace Deno {
       success: boolean;
       outputFiles?: OutputFile[];
     }
+
+    export {}; // only export exports
   }
 
   /** **UNSTABLE**: New API, yet to be vetted.

filename: cli/tsc/dts/lib.deno_webgpu.d.ts
patch: @@ -759,20 +759,32 @@ interface GPUCompilationInfo {
   readonly messages: ReadonlyArray<GPUCompilationMessage>;
 }
 
-/** @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.
@@ -1584,25 +1596,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";

filename: tools/deno.lock.json
patch: @@ -34,7 +34,9 @@
     "jsr:@std/streams@0.221.0": "0.221.0",
     "jsr:@std/yaml@0.221": "0.221.0",
     "jsr:@ts-morph/common@0.24": "0.24.0",
+    "jsr:@ts-morph/common@0.28": "0.28.0",
     "jsr:@ts-morph/ts-morph@23.0.0": "23.0.0",
+    "jsr:@ts-morph/ts-morph@27.0.0": "27.0.0",
     "npm:@types/decompress@4.2.7": "4.2.7",
     "npm:@types/node@*": "24.2.0",
     "npm:decompress@4.2.1": "4.2.1",
@@ -168,11 +170,25 @@
         "jsr:@std/path@~0.225.2"
       ]
     },
+    "@ts-morph/common@0.28.0": {
+      "integrity": "c168c35cd31ebc9cb811bd32d8eedbf331bd7f3e3f3f29bb1a5010f6d7ece94b",
+      "dependencies": [
+        "jsr:@std/fs@1",
+        "jsr:@std/path@1"
+      ]
+    },
     "@ts-morph/ts-morph@23.0.0": {
       "integrity": "5c5bf3187fc3d696ca0cc295e9e024e9c8d52051852cfea67f8e932cfbde0810",
       "dependencies": [
         "jsr:@david/code-block-writer",
-        "jsr:@ts-morph/common"
+        "jsr:@ts-morph/common@0.24"
+      ]
+    },
+    "@ts-morph/ts-morph@27.0.0": {
+      "integrity": "03a93ea311d25a70642db60b376700560a942fc5bfab52718b5e448692d13ed7",
+      "dependencies": [
+        "jsr:@david/code-block-writer",
+        "jsr:@ts-morph/common@0.28"
       ]
     }
   },

filename: tools/generate_types_deno.ts
patch: @@ -4,7 +4,7 @@
 // This script is used to generate the @types/deno package on DefinitelyTyped.
 
 import $ from "jsr:@david/dax@0.42.0";
-import { Node, Project } from "jsr:@ts-morph/ts-morph@23.0.0";
+import { type NamedNode, Node, Project } from "jsr:@ts-morph/ts-morph@27.0.0";
 import * as semver from "jsr:@std/semver@1.0.3";
 
 const rootDir = $.path(import.meta.dirname!).parentOrThrow();
@@ -54,23 +54,23 @@ async function createDenoDtsFile() {
   );
 
   for (const statement of file.getStatementsWithComments()) {
-    if (Node.isCommentStatement(statement)) {
-      const statementText = statement.getText();
-      if (statementText.includes("<reference")) {
-        statement.remove();
-        continue;
-      }
+    if (Node.isCommentNode(statement)) {
+      statement.remove();
+      continue;
     }
-    const shouldKeepKeep = (Node.isModuleDeclaration(statement) ||
-      Node.isInterfaceDeclaration(statement) ||
-      Node.isTypeAliasDeclaration(statement) ||
-      Node.isClassDeclaration(statement)) &&
-      (matchesAny(statement.getName(), [
+    const shouldKeepNode = (namedNode: NamedNode) => {
+      return matchesAny(namedNode.getName(), [
         "Deno",
-      ]) || statement.getName()?.startsWith("GPU"));
-    if (!shouldKeepKeep) {
+      ]) || namedNode.getName()?.startsWith("GPU");
+    };
+    if (Node.isVariableStatement(statement)) {
+      for (const decl of statement.getDeclarations()) {
+        if (!shouldKeepNode(decl)) {
+          decl.remove();
+        }
+      }
+    } else if (!shouldKeepNode(statement)) {
       statement.remove();
-      continue;
     }
   }