66// Manually-written
77// *********************************************************************************************
88
9+ // AllowSharedBufferSource wasn't introduced until TypeScript 5.2.
10+ // But it also didn't include SharedArrayBuffer in the union.
11+ // This broke in ES2024 when ArrayBuffer gained some properties that SharedArrayBuffer didn't.
12+ // So, we use our own definition for AllowSharedBufferSource.
13+
14+ type GPUAllowSharedBufferSource =
15+
16+ | BufferSource
17+ | SharedArrayBuffer ;
18+
19+ // Stronger typing for getContext()
20+
921interface HTMLCanvasElement {
1022 getContext (
1123 contextId :
1224 | "webgpu"
1325 ) : GPUCanvasContext | null ;
1426}
15-
1627interface OffscreenCanvas {
1728 getContext (
1829 contextId :
@@ -21,33 +32,34 @@ interface OffscreenCanvas {
2132}
2233
2334// Defined as an empty interface here to prevent errors when using these types in a worker.
35+
2436interface HTMLVideoElement { }
2537
38+ // Strict types defined to help developers catch a common class of errors.
39+ // This interface defines depth as an undefined, which will cause a type check failure if someone
40+ // attempts to set depth rather than depthOrArrayLayers on a GPUExtent3D (an easy mistake to make.)
41+
2642type GPUOrigin2DStrict =
2743
2844 | Iterable < GPUIntegerCoordinate >
2945 | GPUOrigin2DDictStrict ;
30-
3146interface GPUOrigin2DDictStrict
3247 extends GPUOrigin2DDict {
3348 /** @deprecated Does not exist for GPUOrigin2D. */
3449 z ?: undefined ;
3550}
36-
3751type GPUExtent3DStrict =
3852
3953 | Iterable < GPUIntegerCoordinate >
4054 | GPUExtent3DDictStrict ;
41-
42- // GPUExtent3DDictStrict is defined to help developers catch a common class of errors.
43- // This interface defines depth as an undefined, which will cause a type check failure if someone
44- // attempts to set depth rather than depthOrArrayLayers on a GPUExtent3D (an easy mistake to make.)
4555interface GPUExtent3DDictStrict
4656 extends GPUExtent3DDict {
4757 /** @deprecated The correct name is `depthOrArrayLayers`. */
4858 depth ?: undefined ;
4959}
5060
61+ // Stronger typing for event listeners.
62+
5163/** @internal */
5264interface __GPUDeviceEventMap {
5365 uncapturederror : GPUUncapturedErrorEvent ;
@@ -2865,7 +2877,7 @@ interface GPUQueue
28652877 writeBuffer (
28662878 buffer : GPUBuffer ,
28672879 bufferOffset : GPUSize64 ,
2868- data : AllowSharedBufferSource ,
2880+ data : GPUAllowSharedBufferSource ,
28692881 dataOffset ?: GPUSize64 ,
28702882 size ?: GPUSize64
28712883 ) : undefined ;
@@ -2878,7 +2890,7 @@ interface GPUQueue
28782890 */
28792891 writeTexture (
28802892 destination : GPUTexelCopyTextureInfo ,
2881- data : AllowSharedBufferSource ,
2893+ data : GPUAllowSharedBufferSource ,
28822894 dataLayout : GPUTexelCopyBufferLayout ,
28832895 size : GPUExtent3DStrict
28842896 ) : undefined ;
0 commit comments