typings: rationalise TypedArray types#62174
Conversation
babfd90 to
fe79fa3
Compare
watilde
left a comment
There was a problem hiding this comment.
LGTM. I verified a few things before approving:
TypedArrayConstructor definition — correctly added to globals.d.ts as a union of all 12 concrete constructor types, fully mirroring the existing TypedArray instance union.
Type precision of TypedArrayPrototype and TypedArrayPrototypeGetSymbolToStringTag — both actually improve on the old explicit unions. The previous hardcoded lists had 11 members and were missing Float16Array. The new derived forms (TypedArrayConstructor["prototype"] and TypedArray[typeof Symbol.toStringTag]) automatically include it, making the types more accurate.
readonly removal from TypedArrayOf's rest parameter — this is fine for two reasons. First, readonly on a rest parameter has no effect on the call site (spreading a readonly T[] into a non-readonly rest parameter is accepted by the type checker, as opposed to a regular array parameter like in TypedArrayOfApply, where readonly does matter to callers). Second, this is a .d.ts declaration file with no implementation body, and the underlying %TypedArray%.of doesn't mutate items anyway. The asymmetry with TypedArrayOfApply keeping readonly is intentional and correct.
Adding a constructor helper type allows for some simplification, as well as a fix or two.