Skip to content

Use Array<T> | Iterable<T> ? #169

Description

@sdegutis

In the readme:

Array changed to Iterable for WebIDL sequences in argument positions (but not in return positions).

I think this is to allow you to pass arrays or iterables (such as returned from Array.entries() or Map.values() etc), right? But now I can't index it via renderdesc.colorAttachments[0] because now it thinks it's not an array.

Seems better to use something like Iterable<T> | Array<T> or at least ArrayLike, so I can use this tutorial without issue.

Activity

  1. sdegutis commented on Mar 16, 2025

    @sdegutis
    Author

    Oh wait, that suggestion wouldn't actually solve it... I'd still have to cast it.

  2. kainino0x commented on Mar 17, 2025

    @kainino0x
    Collaborator

    For some past discussion on this topic, see darionco/bikeshed-to-ts#6

    I am still not sure what the right solution is. I was thinking for a long time of having both specialized (Array) and generic (Iterable) versions.

    My general advice is to avoid naming these types in your code where possible. For example if you have a variable initialized as one big literal (most common), let type inference determine the type. For string enums, use e.g. format: 'rgba8unorm' as const so it will infer a narrow type instead of string. For the WebGPU CTS this has solved most cases, so the number of cases where we have to go out of our way to get the correct typing is very small.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions