-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Description
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.
Metadata
Metadata
Assignees
Labels
No labels