Skip to content

Commit 589d66f

Browse files
authored
fix(dts): update some GPU types to not cause errors in upcoming DOM type declarations (#30893)
See microsoft/TypeScript#62496 (comment)
1 parent 9c9bfef commit 589d66f

File tree

4 files changed

+96
-36
lines changed

4 files changed

+96
-36
lines changed

cli/tsc/dts/lib.deno.unstable.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ declare namespace Deno {
162162
success: boolean;
163163
outputFiles?: OutputFile[];
164164
}
165+
166+
export {}; // only export exports
165167
}
166168

167169
/** **UNSTABLE**: New API, yet to be vetted.

cli/tsc/dts/lib.deno_webgpu.d.ts

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -759,20 +759,32 @@ interface GPUCompilationInfo {
759759
readonly messages: ReadonlyArray<GPUCompilationMessage>;
760760
}
761761

762-
/** @category GPU */
763-
declare class GPUPipelineError extends DOMException {
764-
constructor(message?: string, options?: GPUPipelineErrorInit);
765-
766-
readonly reason: GPUPipelineErrorReason;
762+
/**
763+
* The **`GPUPipelineError`** interface of the WebGPU API describes a pipeline failure.
764+
* Available only in secure contexts.
765+
*
766+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/GPUPipelineError)
767+
* @category GPU
768+
*/
769+
interface GPUPipelineError extends DOMException {
770+
/**
771+
* The **`reason`** read-only property of the GPUPipelineError interface defines the reason the pipeline creation failed in a machine-readable way.
772+
*
773+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/GPUPipelineError/reason)
774+
*/
775+
readonly reason: "validation" | "internal";
767776
}
768777

769778
/** @category GPU */
770-
interface GPUPipelineErrorInit {
771-
reason: GPUPipelineErrorReason;
772-
}
779+
declare var GPUPipelineError: {
780+
prototype: GPUPipelineError;
781+
new (message: string, options: GPUPipelineErrorInit): GPUPipelineError;
782+
};
773783

774784
/** @category GPU */
775-
type GPUPipelineErrorReason = "validation" | "internal";
785+
interface GPUPipelineErrorInit {
786+
reason: "validation" | "internal";
787+
}
776788

777789
/**
778790
* Represents a compiled shader module that can be used to create graphics or compute pipelines.
@@ -1584,25 +1596,55 @@ interface GPUDeviceLostInfo {
15841596
readonly message: string;
15851597
}
15861598

1587-
/** @category GPU */
1588-
declare class GPUError {
1599+
/**
1600+
* The **`GPUError`** interface of the WebGPU API is the base interface for errors surfaced by GPUDevice.popErrorScope and the GPUDevice.uncapturederror_event event.
1601+
* Available only in secure contexts.
1602+
*
1603+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/GPUError)
1604+
* @category GPU
1605+
*/
1606+
interface GPUError {
1607+
/**
1608+
* The **`message`** read-only property of the A string.
1609+
* The **`message`** read-only property of the GPUError interface provides a human-readable message that explains why the error occurred.
1610+
*
1611+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/GPUError/message)
1612+
*/
15891613
readonly message: string;
15901614
}
15911615

15921616
/** @category GPU */
1593-
declare class GPUOutOfMemoryError extends GPUError {
1594-
constructor(message: string);
1595-
}
1617+
declare var GPUError: {
1618+
prototype: GPUError;
1619+
new (): GPUError;
1620+
};
15961621

15971622
/** @category GPU */
1598-
declare class GPUValidationError extends GPUError {
1599-
constructor(message: string);
1600-
}
1623+
interface GPUOutOfMemoryError extends GPUError {}
16011624

16021625
/** @category GPU */
1603-
declare class GPUInternalError extends GPUError {
1604-
constructor(message: string);
1605-
}
1626+
declare var GPUOutOfMemoryError: {
1627+
prototype: GPUOutOfMemoryError;
1628+
new (message?: string): GPUOutOfMemoryError;
1629+
};
1630+
1631+
/** @category GPU */
1632+
interface GPUValidationError extends GPUError {}
1633+
1634+
/** @category GPU */
1635+
declare var GPUValidationError: {
1636+
prototype: GPUValidationError;
1637+
new (message?: string): GPUValidationError;
1638+
};
1639+
1640+
/** @category GPU */
1641+
interface GPUInternalError extends GPUError {}
1642+
1643+
/** @category GPU */
1644+
declare var GPUInternalError: {
1645+
prototype: GPUInternalError;
1646+
new (message?: string): GPUInternalError;
1647+
};
16061648

16071649
/** @category GPU */
16081650
type GPUErrorFilter = "out-of-memory" | "validation" | "internal";

tools/deno.lock.json

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/generate_types_deno.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// This script is used to generate the @types/deno package on DefinitelyTyped.
55

66
import $ from "jsr:@david/[email protected]";
7-
import { Node, Project } from "jsr:@ts-morph/ts-morph@23.0.0";
7+
import { type NamedNode, Node, Project } from "jsr:@ts-morph/ts-morph@27.0.0";
88
import * as semver from "jsr:@std/[email protected]";
99

1010
const rootDir = $.path(import.meta.dirname!).parentOrThrow();
@@ -54,23 +54,23 @@ async function createDenoDtsFile() {
5454
);
5555

5656
for (const statement of file.getStatementsWithComments()) {
57-
if (Node.isCommentStatement(statement)) {
58-
const statementText = statement.getText();
59-
if (statementText.includes("<reference")) {
60-
statement.remove();
61-
continue;
62-
}
57+
if (Node.isCommentNode(statement)) {
58+
statement.remove();
59+
continue;
6360
}
64-
const shouldKeepKeep = (Node.isModuleDeclaration(statement) ||
65-
Node.isInterfaceDeclaration(statement) ||
66-
Node.isTypeAliasDeclaration(statement) ||
67-
Node.isClassDeclaration(statement)) &&
68-
(matchesAny(statement.getName(), [
61+
const shouldKeepNode = (namedNode: NamedNode) => {
62+
return matchesAny(namedNode.getName(), [
6963
"Deno",
70-
]) || statement.getName()?.startsWith("GPU"));
71-
if (!shouldKeepKeep) {
64+
]) || namedNode.getName()?.startsWith("GPU");
65+
};
66+
if (Node.isVariableStatement(statement)) {
67+
for (const decl of statement.getDeclarations()) {
68+
if (!shouldKeepNode(decl)) {
69+
decl.remove();
70+
}
71+
}
72+
} else if (!shouldKeepNode(statement)) {
7273
statement.remove();
73-
continue;
7474
}
7575
}
7676

0 commit comments

Comments
 (0)