microsoft / microsoft/TypeScript
Adding generic parameter to a lambda function removes typing from the function argument
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
TypeScript Version: 3.2.2
Search Terms: generic removes parameter type
Code
// OKAY
// declare const labmda function with typings, then implement with minimal type annotations.
// "input" has type of "string".
export const foo: (input: string) => string
= (input) => (input);
// OKAY
// declare const lambda generic function without typings, then implement with full inline type annotations.
// "input" has type of "string".
export const bar
= <TResult>(input: string) => ({ } as Partial<TResult>);
// ERROR
// declare const labmda generic function with typings, then implement with minimal type annotations.
// "input" has type of "any".
export const baz: <TResult>(input: string) => Partial<TResult>
= <TResult>(input) => ({ [input]: input } as Partial<TResult>);
Expected behavior:
input is typed as string.
Actual behavior:
input is typed as any.
(NOTE: options -> noImplicitAny to have the issue highlighted as an error.)
Related Issues:
https://github.com/Microsoft/TypeScript/issues/18606
I think this issue might be related, but I don't understand it enough to judge.
If this is the same issue then the answer is "this is correct, and a limitation of the type system", which is fair enough.
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 noImplicitAny abilitato, quindi confronta le tre dichiarazioni lambda e la issue correlata #18606. Traccia il modo in cui il tipaggio contestuale viene applicato all’assegnazione della lambda generica. Il lavoro è completato quando si determina se l’argomento debba essere inferito come string e si aggiunge un test di regressione se il comportamento viene confermato come bug.
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
- Abbastanza chiara
- Idoneità per principianti
- 38/100