Microsoft/TypeScript
在 GitHub 查看Suggestion: use numeric literals for `BYTES_PER_ELEMENT`
Open
#59,557 创建于 2024年8月8日
Domain: lib.d.tsExperience EnhancementHelp WantedSuggestion
仓库指标
- Star
- (48,455 star)
- PR 合并指标
- (平均合并 6天 17小时) (30 天内合并 9 个 PR)
描述
⚙ Compilation target
ES5+
⚙ Library
lib.es5.d.ts, lib.es2022.bigint.d.ts
Missing / Incorrect Definition
Suggesting to change the BYTES_PER_ELEMENT static and instance properties as follows:
interface Uint8Array {
// ...
- readonly BYTES_PER_ELEMENT: number;
+ readonly BYTES_PER_ELEMENT: 1;
// ...
}
interface BigInt64ArrayConstructor {
// ...
- readonly BYTES_PER_ELEMENT: number;
+ readonly BYTES_PER_ELEMENT: 8;
// ...
}
Etc.
Sample Code
declare function fn(bytesPerElement: 1 | 2 | 4 | 8): void
// currently reports "Argument of type 'number' is not assignable to parameter of type '1 | 2 | 4 | 8'".
fn(Uint32Array.BYTES_PER_ELEMENT)