microsoft / microsoft/TypeScript

Type aliases not being resolved for some functions types

Aperta
#30,312 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

TypeScript Version: 3.4.0-dev.20190310

Search Terms:

Resolve / flatten / simplify type aliases for function calls

resolve type aliases

Code

let subject = {a:1,b:2,c:3,d:4}

type thisResolves = Pick<typeof subject, 'a' | 'b'>

let thisDoesnt = pick(subject, ['a', 'b'])

declare function pick<T, K extends keyof T>(obj: T, keys: K[]): Pick<T,K>

Expected behavior:

The Quick Info type of thisDoesnt resolves to { a: number, b: number}

Actual behavior:

The Quick Info type of thisDoesnt resolves to Pick<{ a: number, b: number, c: number, d: number}, 'a' | 'b'>

Playground Link: here

Related Issues:

I've seen in other issues that type aliases are eagerly resolved (e.g. https://github.com/Microsoft/TypeScript/issues/13095#issuecomment-268627521 and https://github.com/Microsoft/TypeScript/issues/16798#issuecomment-324753135). This is a case where that behavior is useful, since reading through a lot of Pick<Foo<Bar<... in VS Code makes it difficult to figure out the true source of a type error.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione collegata in Playground ed esamina l'output di Quick Info per thisDoesnt rispetto a thisResolves. Traccia il modo in cui il type checker di TypeScript o il language service presenta il risultato di Pick, quindi verifica che il tipo visualizzato sia { a: number, b: number } senza modificare il comportamento del tipo sottostante.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers, developer-experience
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.