-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypedArray-related errors with TypeScript 5.7.2 #58
Comments
@rbuckton perhaps you could give a hint on what might be wrong here? The typings depend on a union of |
When you union constructor types, generic signatures must match exactly. Since each constructor type in the union produces a different return type, they are excluded from the resulting set. In the long term, I can look into adding non-generic overloads for these cases. As a workaround, you can define an alternative union for generic use: type TypedArray<TArrayBuffer extends ArrayBufferLike = ArrayBuffer> =
| Uint8Array<TArrayBuffer>
| Int8Array<TArrayBuffer>
| Uint16Array<TArrayBuffer>
| Int16Array<TArrayBuffer>
| Uint32Array<TArrayBuffer>
| Int32Array<TArrayBuffer>
| Float32Array<TArrayBuffer>
| Float64Array<TArrayBuffer>;
type TypedArrayConstructor = (
| Uint8ArrayConstructor
| Int8ArrayConstructor
| Uint16ArrayConstructor
| Int16ArrayConstructor
| Uint32ArrayConstructor
| Int32ArrayConstructor
| Float32ArrayConstructor
| Float64ArrayConstructor
) & {
new <TArrayBuffer extends ArrayBufferLike = ArrayBuffer>(arrayBuffer: TArrayBuffer, byteOffset?: number, length?: number): TypedArray<TArrayBuffer>;
}; |
@rbuckton thank you for the prompt response! I can't get it to work so far, getting some errors that are cryptic to me, but perhaps I should just silence the error because it is getting into territory too complicated for simple typing I intended for the library. My JSDoc looks like this: /** @template {ArrayBufferLike} T
* @typedef {Uint8Array<T> | Int8Array<T> | Uint16Array<T> | Int16Array<T> | Uint32Array<T> | Int32Array<T> | Float32Array<T> | Float64Array<T>} TypedArray<T = ArrayBuffer> */
/** @typedef {(Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor) & {new <T extends ArrayBufferLike = ArrayBuffer>(arrayBuffer: T, byteOffset?: number, length?: number): TypedArray<T>}} TypedArrayConstructor */ And one of the errors is: index.js:44:49 - error TS2345: Argument of type 'Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | ... 4 more ... | Float64ArrayConstructor' is not assignable to parameter of type 'TypedArrayConstructor | undefined'.
Type 'Uint8ClampedArrayConstructor' is not assignable to type 'TypedArrayConstructor | undefined'.
Type 'Uint8ClampedArrayConstructor' is not assignable to type 'Int8ArrayConstructor & (new <T extends ArrayBufferLike = ArrayBuffer>(arrayBuffer: T, byteOffset?: number | undefined, length?: number | undefined) => TypedArray<...>)'.
Type 'Uint8ClampedArrayConstructor' is not assignable to type 'Int8ArrayConstructor'.
The types of 'prototype.filter(...)[Symbol.toStringTag]' are incompatible between these types.
Type '"Uint8ClampedArray"' is not assignable to type '"Int8Array"'.
44 return new Flatbush(numItems, nodeSize, ArrayType, undefined, data, byteOffset);
~~~~~~~~~ |
This is tracked by microsoft/TypeScript#60745. |
Do the union constituents match what they were previously? From the error you provided it sounds like |
Upgrading TypeScript and then running
npm test
produces the following errors:I don't know why it fails to pickup the 3-argument version of the typed constructors. Probably related to microsoft/TypeScript#59417? Any help from people more well versed in TypeScript appreciated.
The text was updated successfully, but these errors were encountered: