microsoft / microsoft/TypeScript
keyof of 'mixed' class equals to `string | number`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
TypeScript Version: 3.4.3 or 3.5.0-dev.20190427
Search Terms: keyof, anonymous class
Code
type AnyClass = new (...args: any[]) => any;
const mixin = <T extends AnyClass>(Class: T) => class extends Class {a: string};
const Cl = mixin(class {b = 123});
const inst = new Cl();
inst. // <- IntelliSense works fine here and suggests 'a' and 'b' properties
type Keys = keyof typeof inst; // Keys = string | number
Expected behavior:
Keys to be equal to 'a' | 'b'
Actual behavior:
Keys to be equal to string | number
Playground Link: ts-playground
Description:
I'm sorry if that is a known bug ot expected behaviour. I did not find a duplicate.
Class C is a result of extension of some other class A provided as a function argument and class B which is declared inside the function body. Such class C works fine for the most part, but keyof InstanceType<typeof C> returns string | number.

While IntelliSense works fine:

I'll be glad if you suggest any workarounds for this issue.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo l'esempio nel TypeScript Playground collegato con le versioni indicate e conferma il tipo inferito di keyof typeof inst. Traccia la gestione di keyof da parte del compilatore per la classe anonima mista e aggiungi la copertura per l'esempio, in modo che il risultato sia 'a' | 'b' anziché string | number.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100