microsoft / microsoft/TypeScript

Type inference regression on function calls not saved to variables, due to #61668

Aperta
#62,071 1 commento 5 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Domain: check: Type Inference Help Wanted Possible Improvement
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

### 🔎 Search Terms

61668 inference overload regression tuple

### 🕗 Version & Regression Information

- This changed in commit or PR #61668

### ⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.9.0-beta#code/PTAEGIDYEZMgOUBjAFgQwHYHMCmBnUAFxR1AEsMAzHAJxwyVMpoHsBbUAbQwFc2AjWgBpQeQjQpYAukRagAFLwG0APmInYAlJykAoACY4kAGzR1QlHg0JkWGULkIA5PvM0AuUAAVWbMnhwAHiVBGgA+AG4DI1NzS2tbe0cAZXE3Tx92fyD1SUjokzMmKyQbO1AeAIAVHgAHYxx5QjqGz24+UJFc7CkPUAA3FjJ9KKQ7MVBa0ABeb19sgDo6PBZjfsadTQXienk3GbC5rICFtGNjeU5HFzY3ERS0zV6tnYx5Spwa+pxNKKA

### 💻 Code

```ts
declare function getNum(): Promise;
declare function getStr(): Promise;
declare function useTuple(tuple: [number, string]): void;
const p = Promise.resolve([]).then(() => Promise.all([getNum(), getStr()])).then(useTuple);
```

### 🙁 Actual behavior

The `Promise.all` infers to `Promise<(number|string)[]>`.

### 🙂 Expected behavior

The `Promise.all` should infer `Promise<[number, string]>`.

### Additional information about the issue

This only happens when the `Promise.all` call is directly returned. If I instead write

```
const p = Promise.all([getNum(), getStr()]);
return p;
```

then it infers the tuple correctly again, even without doing anything that would suggest it should infer the type differently.

This PR also impacted inference of enums: in [another example](https://www.typescriptlang.org/play/?ts=5.9.0-beta#code/PTAEDkHkBUFEC5QHsBGBnApgJwG7baAJYEDGSAdgC5YCGONWhNVAUCQDY1oEDKArigBWGEpQA80AHygA3i1DJ02PFjSIAFOvrs+GRNACUoALzScSQgBMDAbQC6J0PYDc80GXJpqfUUizqAB0Z6SgxQAH1tXX0jGQBfFgSWDHI+AFtQAFkkSzC5BQBBRwByGmKAGjcAIRKUCsSWNk5uUB5lQhI8tzScjABCRH4hEXFs3MlXBNyOBjCAMz5yUUIKdywMGlDskgBrMUghSUCsJAC1WRsABSJyUB2MAE8kOdADwTsAfkQ3q7s4g0Q5isrjY602GG2ezauA6GCO+VAIAgMAQoGgAAtiDc5tgUp13OjmABzDCWG6gADEADYAIxUqkADm6vUQ5AwAHdWgJhKJ1GMMAA6AoGSr-EEeLygHq5RxszlDHmUPm9IUGVxIhSgAB6H1BGy2SF2YmhOFh8OlGDFLCAA), I pass `{mode: new Subject(Mode.A)}` into a function that fails because it infers `Subject` while if I save a temporary `const mode = new Subject(Mode.A);` then it infers `Subject` and passes.

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 TypeScript Playground e confronta il cambiamento nell’inferenza introdotto da PR #61668. Segui il percorso di restituzione diretta per Promise.all e il caso contrapposto con una variabile temporanea, quindi verifica l’esempio enum come seconda regressione. Il lavoro è completo quando entrambi gli esempi inferiscono i tipi tupla ed enum come descritto, senza introdurre regressioni nel comportamento esistente.

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
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.