microsoft / microsoft/TypeScript
Enhance members of literal type like const array type (e.g. string literal types should have literal length property)
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
The const array type, its principle members are also be the constant. When define a const array [number, string, boolean], its length type be 3. Also, when access to special index, the type also points the exact const type.
function const_array(): void
{
let elements: [number, string, false] = [3, "something", false];
let length: 3 = elements.length;
let first: number = elements[0];
let second: string = elements[1];
let third: false = elements[2];
}
However, the literal type is not like the const array. When define a literal type "something", its length be not 9 but number. Also, when access to a special index, the type is not a special literal type but a string type.
function literal(): void
{
let word: "something" = "something" as const;
let length: number = something.length; // not 9 but number
let first: string = word[0]; // not "s" but string
let second: string = word[1]; // not "o" but string
let third: string = word[2]; // not "m" but string
}
What about enhancing the literal type to be like the const array type?
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
No files or tests are named. Start by locating the type-checking paths for string-literal property access and indexed access, then compare their behavior with tuple handling. Done means literal strings expose a literal length and literal character types at known indexes, with appropriate type-checking tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100