microsoft / microsoft/TypeScript
Enhance members of literal type like const array type (e.g. string literal types should have literal length property)
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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?
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Es werden keine Dateien oder Tests genannt. Beginne damit, die Pfade der Typprüfung für den Property-Zugriff mit String-Literalen und den Indexzugriff zu finden, und vergleiche dann ihr Verhalten mit der Behandlung von Tupeln. Als abgeschlossen gilt die Aufgabe, wenn Literal-Strings eine Literal-Länge und an bekannten Indizes Literal-Zeichentypen liefern, zusammen mit geeigneten Typprüfungs-Tests.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100