microsoft / microsoft/TypeScript
Suggestion: use numeric literals for `BYTES_PER_ELEMENT`
Open
Nobody has claimed this yet.
Domain: lib.d.ts
Experience Enhancement
Help Wanted
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
⚙ 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)
Documentation Link
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect the typed array declarations in lib.es5.d.ts and lib.es2022.bigint.d.ts, including the static and instance BYTES_PER_ELEMENT properties. Compare the declarations with the issue's proposed literal values and verify that the sample calls accepting 1 | 2 | 4 | 8 type-check correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100