You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Accessing the properties of size in a GPUTextureDescriptor requires first casting it as a GPUExtent3DDictStrict:
const texture: GPUTextureDescriptor = {
size: { width: 1, height: 2, depthOrArrayLayers: 2 }, // No TS error here
usage: GPUTextureUsage.COPY_DST,
format: navigator.gpu.getPreferredCanvasFormat()
};
texture.size.width // Property 'width' does not exist on type 'GPUExtent3DStrict'.
texture.size.depthOrArrayLayers // Property 'depthOrArrayLayers' does not exist on type 'GPUExtent3DStrict'.
const size = texture.size as GPUExtent3DDictStrict;
size.width // OK
size.depthOrArrayLayers // OK
I understand this is probably because size can either be an Iterable or an object, but this isn't very ergonomic.
Perhaps GPUTextureDescriptor could take an optional generic parameter to determine the type of size?
Either way allowing size to be a union type makes dynamically handling GPUTextureDescriptors more complicated than it should be, since it forces you to check the type first.
I realize this is more of a spec issue than a types issue, but ideally size should just have one type. The drawbacks of having to check at runtime if it's an object or Iterable far outweigh the convenience of defining it more concisely as an array.
The text was updated successfully, but these errors were encountered:
pietrovismara
changed the title
Incorrect type for size of GPUTextureDescriptor
Unergonomic type for size of GPUTextureDescriptor
Feb 29, 2024
Accessing the properties of
size
in aGPUTextureDescriptor
requires first casting it as aGPUExtent3DDictStrict
:I understand this is probably because
size
can either be anIterable
or an object, but this isn't very ergonomic.Perhaps
GPUTextureDescriptor
could take an optional generic parameter to determine the type ofsize
?Either way allowing
size
to be a union type makes dynamically handlingGPUTextureDescriptor
s more complicated than it should be, since it forces you to check the type first.I realize this is more of a spec issue than a types issue, but ideally
size
should just have one type. The drawbacks of having to check at runtime if it's an object orIterable
far outweigh the convenience of defining it more concisely as an array.The text was updated successfully, but these errors were encountered: