microsoft / microsoft/TypeScript
Broken property suggestions due to a successfully contextually typed function
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
```ts
declare function makeRequest<
QueryParam
>(
getFn: (client: { prop: number }) => QueryParam,
params: NoInfer,
): void;
// Hovering over `makeRequest` shows that `QueryParam` is inferred as `unknown` and `params` is obstensibly typed as `unknown` which is incongruous with this call is an error.
makeRequest(
(client) => client,
// Using autocomplete here suggests globals, not `prop` like it should.
{},
// ^ Argument of type '{}' is not assignable to parameter of type '{ prop: number; }'.
);
makeRequest(
(client: { prop: number }) => client,
// Using autocomplete here now suggests keys.
{},
);
```
Sub-part of https://github.com/microsoft/TypeScript/issues/46916#issuecomment-2759515773 with parts pointed out with https://github.com/microsoft/TypeScript/issues/46916#issuecomment-2760441648
See @Andarist's analysis at https://github.com/microsoft/TypeScript/issues/46916#issuecomment-2760441648
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 con la riproduzione minima in TypeScript nell’issue e leggi l’analisi collegata nell’issue #46916 e nei relativi commenti. Segui il contextual typing e l’inferenza per la funzione generica, quindi verifica che QueryParam venga inferito dal callback e che il completamento automatico per params offra prop senza un’annotazione esplicita del callback.
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à
- Attiva
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100