microsoft / microsoft/TypeScript
TypedArray constructor compile error
オープン
@rbuckton がすでに取り組んでいます。
2025年2月7日 から。
Needs Investigation
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
🔎 Search Terms
When creating a class for a typed array, if this class is returned by indexing into an object, I get a compile error.
See attached playground link.
🕗 Version & Regression Information
- This changed between versions 5.7.3 and 5.4.2, it used to work in 5.4.2
⏯ Playground Link
💻 Code
export type TypedArrayConstructor =
| Uint8ArrayConstructor
| Uint16ArrayConstructor
| Uint32ArrayConstructor
| Int8ArrayConstructor
| Int16ArrayConstructor
| Int32ArrayConstructor
| Float32ArrayConstructor
export const Constants = {
BYTE: 5120,
UNSIGNED_BYTE: 5121,
SHORT: 5122,
UNSIGNED_SHORT: 5123,
INT: 5124,
UNSIGNED_INT: 5125,
FLOAT: 5126,
}
export const arrayByType = {
[Constants.BYTE] : Int8Array,
[Constants.UNSIGNED_BYTE] : Uint8Array,
[Constants.SHORT] : Int16Array,
[Constants.UNSIGNED_SHORT] : Uint16Array,
[Constants.INT] : Int32Array,
[Constants.UNSIGNED_INT] : Uint32Array,
[Constants.FLOAT] : Float32Array,
} as const;
const buffer = new ArrayBuffer();
// Ok
{
const ArrayClass: TypedArrayConstructor = Int8Array;
const c = new ArrayClass(buffer, 0, 1);
}
// Compile Error
{
const componentType = Constants.BYTE;
const ArrayClass: TypedArrayConstructor = arrayByType[componentType];
const c = new ArrayClass(buffer, 0, 1); // Expected 0-1 arguments
}
🙁 Actual behavior
The last line returns a compile error.
🙂 Expected behavior
There should be no compile errors.
Additional information about the issue
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
評価
この issue はまだ評価されていません。