microsoft / microsoft/TypeScript

`silentNeverType` leak in contextual parameter types coming from anonymous non-aliased object type instantiations

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

Nessuno ha ancora preso questa issue.

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

Descrizione

### 🔎 Search Terms

silent never type return type inference alias propagating anonymous object

### 🕗 Version & Regression Information

- This is the behavior in every version I tried

### ⏯ Playground Link

https://www.typescriptlang.org/play/?ts=6.0.0-dev.20250827#code/JYOwLgpgTgZghgYwgAgAoB4AqA+ZBvAKGWTAAsIQAuZACgHsQYBXAGxmBZYgBNqaA3OCyYRqmAJTIAvLiYgA1iDoB3EJJnI5ilSADcBAL4ECoSLEQpUAYQYBnMFCYIwdKPiLIQEZcizYaEAAeEAhMLlB8UBC2dCz8orSCwgkS0rj8dMDc6umZ2dQYOPpGBNwhLHBRyIJuqAU2IPaOzq76peWVKMwgzsAMyDB0dACMfjSBfDlo6HjIZfCsYGLIBtjiYm0IdmDIUbaLw9IDQ8M0NFOExFFgTFAgnt5oZ3ux8RceV9GvEPrExAD0-2QAD0APweAziYpQ4xgACeAAcUAB1YBkAAiEAWLDAfiOs3mcEWywMbTKCAqVW6vX6gzoACYxhNaFMMKiMViiTi-GsNsYto0dntFvSjnT6Wd3p8bncHj5UM8vnEIFK-i9lb8-oCQeDiJDoWSOlS5DT7nSAMxMyZpaYAbUwAF1echMJttrtootzWKhubJTbLh6ZfcvPLFTFlarPhH4pqAUCwRCYfrjOTKV0TWA+mahgAWK0sm0YAmc4n4ZAIqB0BEklbO13893CnG5n10XP+jSB663EOPBU0dVvAMfD0xn6j7WJvXJmHtCmdAaZ7PHOgAVgL5yLMzmpZx1HtDrr6xdbsFY8Wa7ba87uG7EGDcqeg6Vw67o6HE7+yCnupWs90IA

### 💻 Code

```ts
interface P {
then: (onfulfilled: (value: T) => unknown) => unknown;
}

interface PConstructor {
new (executor: (resolve: (value: T) => void) => void): P;
}

declare var P: PConstructor;

declare function foo1(x: () => P<{ default: T }>): T;

const result1 = foo1(() => {
return new P((resolve) => {
resolve;
});
});

type WithDefault = { default: T };

declare function foo2(x: () => P>): T;

const result2 = foo2(() => {
return new P((resolve) => {
resolve;
});
});

declare function foo3(x: () => P<[T]>): T;

const result3 = foo3(() => {
return new P((resolve) => {
resolve;
});
});

declare function foo4(x: () => P<{ default: { prop: T } }>): T;

const result4 = foo4(() => {
return new P((resolve) => {
resolve;
});
});

declare function foo5(x: () => P<{ default: [T] }>): T;

const result5 = foo5(() => {
return new P((resolve) => {
resolve;
});
});
```

### 🙁 Actual behavior

Only `foo2` and `foo3` have errors and we can see that their inner `resolve`s reference `never`

### 🙂 Expected behavior

All of those should consistently error and `resolve` should be typed as `(value: unknown) => void`. Specifically, `foo1` and `foo2` are the almost the same signatures but `foo2` is using a type alias in its declaration which changes the inference behavior. This is strong indication of the bug here

### Additional information about the issue

_No response_

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 riproducendo l’esempio di Playground e confrontando l’inferenza dei parametri contestuali da foo1 a foo5, in particolare le istanziazioni di oggetti anonimi rispetto al tipo alias WithDefault. Traccia il percorso di inferenza dei tipi che produce il tipo resolve interno; il lavoro è completato quando tutti e cinque i casi riportano coerentemente errori e la risoluzione del tipo risulta accettare unknown.

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à
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.