microsoft / microsoft/TypeScript
Low priority inference trumps a much better inference that can be made from a generic signature
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 Search Terms
inference generic signature type parameters low priority
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
declare function defineComponent<Props extends Record<string, any>>(
setup: (props: Props) => void,
options?: {
props?: (keyof Props)[];
},
): (props: Props) => unknown;
const res1 = defineComponent(
<T extends string>(_props: { msg: T }) => {
return () => {};
}
);
res1
// ^? const res1: <T extends string>(props: { msg: T; }) => unknown
const res2 = defineComponent(
<T extends string>(_props: { msg: T }) => {
return () => {};
},
{
props: ["msg"],
},
);
res2
// ^? const res2: (props: { msg: any; }) => unknown
🙁 Actual behavior
A low-priority inference made from keyof Props prevents inference from the generic signature
🙂 Expected behavior
I'd expect both of those to infer the same result: <T extends string>(props: { msg: T; }) => unknown
Additional information about the issue
There is an existential question to be asked here... what is a low-priority inference in the first place? :P Where is the line? Should every inference priority other than InferencePriority.None be treated as low-priority here?
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
Riproduci la differenza di inferenza nel TypeScript Playground collegato, iniziando dalla firma generica e dal percorso di inferenza di keyof Props descritto nell’issue. Traccia come viene gestita l’inferenza a bassa priorità, quindi verifica che res2 inferisca la stessa firma generica di res1 senza introdurre regressioni nei casi di inferenza correlati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100