microsoft / microsoft/TypeScript

`silentNeverType` leak through return type inference

Abierto
#62,824 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Bug Domain: check: Type Inference Help Wanted
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

### 🔎 Search Terms

silent never leak reverse mapped types nested calls return type inference

### 🕗 Version & Regression Information

- This is the behavior in every version I tried

### ⏯ Playground Link

https://www.typescriptlang.org/play/?noEmit=true&ts=6.0.0-dev.20251202#code/C4TwDgpgBAaghgGwK4QM4B4AqA+KBeKTAbQGsIQB7AM0IF0BuAKEdEigFk4BjACwEsAdhADCFAcAgAPYPigAlCFwoAnACbpUwZYIDmAGihwBIbE0aCJyqt2gAFOMrgBbCJb4AvCKoDyAIwBWijIA3oxQUKwQAFxQmtoCOkzhYA7OqAD8MUgCJAIUAO4CTAC+zJFQAIJcwHxiAGLZ1bUC6GGEouJSMl0QAqqoHNz8Qh0S0nptmPaOTgM9fQPTzq4Q2p4+AUFEAEQpM6jbtFAAPlDZqhBUgl4T4ZhVNWJQ8-1QSy5u636B1RO4BKFwgAKaqSGKYUZdAx7NLg96oACUMQAbhQ+KoklAAPoUJDALH3JpiTKEB7NEpmcqYCjvFZrLzfIKtO60z5eThgZ7SXqvBRKNTM8KxLS6W5C1mrDwMzbVHYw2aHE5nPqXa6qNrYP6yeDINDoQFQIgAaSggigZEoNCmqQ+kvWHKgADJhfEdLQYgbwpEYkbMckbag4Ta6VLVBzjQw2sUSqYyuBoKIEAggmSxBhJpDpFyJAtBrxrpngGLrftszzFsG2RsfsA5QHFadzqqhKotQQgW1PVAlJ1xm1wr0AI4oFBi4oe-vdsRjYDgwt+54CYcQFAxIHcR4CNcI-C4VHond4PdojFRsXywOEeETQ-H9FmC5cBAOaBURqbxfLlCpgTpu6Fstc04fMRmnKFJnhQDXglelqy2XZ6yORsVSuFtix-KCKxmEMvhlGQCBg0NGV+RhsA7cIlCTIIYkTZNqh-DAITA8YrwDTVGCRSoiQEBoBG4rBCwMEs0iEn9Y0YR9n2UV932aWJXCQMBBSY3tum5IChgLZii0mBjMPkRQVHUSc4lFSdCNwms632BtlQuVCvA1WRgmKP4gQNSJUDFDdmi8xhxygDz4wyD0p1UkkVJnKBozaHy0xJLtjVNARzXIahSW41B3S4zdeP4yd-20sUhQyzdUAjYqhWpCzpRrLAGOwSdY3CGLik4-dT0YVAFLAdzYsyicStUCgAGVgCQKgqBiIcRwgBigSBLFoQDGIBCQJxfFWW9ArascJjasxuvG3qDTi39BqFYaxomqbP1m+bFuW-ZVvWzblG2lyEUq4bvGAHhVmuya1yWqALxiUyEg+1yz38hFDp6vrwjOy8uyu8agbulc5syhaQbBqA1o2rbdx2r7Jx+v6AfR27FpiIwQCe2EXV0KG9thpggA

### 💻 Code

```ts
type Values = T[keyof T];

type MachineContext = Record;

interface ParameterizedObject {
type: string;
params?: unknown;
}

type ActionFunction<
TContext extends MachineContext,
TParams extends ParameterizedObject["params"] | undefined,
TAction extends ParameterizedObject,
> = {
(ctx: TContext, params: TParams): void;
_out_TAction?: TAction;
};

type ToParameterizedObject<
TParameterizedMap extends Record<
string,
ParameterizedObject["params"] | undefined
>,
> = Values<{
[K in keyof TParameterizedMap & string]: {
type: K;
params: TParameterizedMap[K];
};
}>;

type CollectActions<
TContext extends MachineContext,
TParams extends ParameterizedObject["params"] | undefined,
> = (
{
context,
enqueue,
}: {
context: TContext;
enqueue: (action: () => void) => void;
},
params: TParams,
) => void;

declare function enqueueActions<
TContext extends MachineContext,
TParams extends ParameterizedObject["params"] | undefined,
TAction extends ParameterizedObject = ParameterizedObject,
>(
collect: CollectActions,
): ActionFunction;

declare function setup<
TContext extends MachineContext,
TActions extends Record<
string,
ParameterizedObject["params"] | undefined
> = {},
>({
types,
actions,
}: {
types?: { context?: TContext };
actions?: {
[K in keyof TActions]: ActionFunction<
TContext,
TActions[K],
ToParameterizedObject
>;
};
}): void;

setup({
actions: {
doStuff: enqueueActions((_, params: number) => {}),
},
});

setup({
actions: {
doStuff: enqueueActions((_, params: number) => {}),
doOtherStuff: (_, params: string) => {},
},
});

setup({
actions: {
doStuff: enqueueActions((_, params: number) => {}),
doOtherStuff: (_: any, params: string) => {},
},
});
```

### 🙁 Actual behavior

First 2 calls mention such a relationship check failure in the error message:
```
Type 'ActionFunction' is not assignable to type 'ActionFunction'.
```

Notice **never** there. This is quite weird an unexpected as there is no `never` in sight here. It turns out this is a `silentNeverType` that leaked through.

### 🙂 Expected behavior

At the very least, I would expect it to error with consistent error messages mentioning `unknown` instead of `never`. Even better, if it could behave closer to a *very similar* version of this code: [TS playground](https://www.typescriptlang.org/play/?noEmit=true&ts=6.0.0-dev.20251202#code/C4TwDgpgBAaghgGwK4QM4B4AqA+KBeKTAbQGsIQB7AM0IF0BuAKEdEigFk4BjACwEsAdhADCFAcAgAPYPigAlCFwoAnACbpUwZYIDmAGihwBIbE0aCJyqt2gAFOMrgBbCJb4AvCKoDyAIwBWijIA3oxQUKwQAFxQmtoCOkzhYA7OqAD8MUgCJAIUAO4CTAC+zJFQAIJcwHxiAGLZ1bUC6GGEouJSMl0QAqqoHNz8Qh0S0nptmPaOTgM9fQPTzq4Q2p4+AUFEAEQpM6jbtFAAPlDZqhBUgl4T4ZhVNWJQ8-1QSy5u636B1RO4BKFwgAKaqSGKYUZdAx7NLg96oACUMQAbhQ+KoklAAPoUJDALH3JpiTKEB7NEpmcqYCjvFZrLzfIKtO60z5eThgZ7SXqvBRKNTM8KxLS6W5C1mrDwMzbVHYw2aHE5nPqXa6qNrYP6yeDINDoQFQIgAaSggigZEoNCmqQ+kvWHMMAxNADJhfEdLQYgbwpEYi63bpMckbag4Ta6VLVBzjQw2sUSqYyuBoKIEAggmSxBhJpDpFyJAtBrxrrngGLrft8zzFuG2RsfsA5SHFadzqqhKotQQgW1vVAlJ1xm1wr0AI4oFBi4pe4f9sRjYDg0tB54CccQFAxIHcR4CLcI-C4VHog94I9ojFxsXy0OEeETU-n9FmC5cBAOaBURq71frlCZgRszuUsq0LThixGecoUmeFQNeCV6XrLZdmbI5WxVK4O3LAC4JrGYIy+GUZAIBDI0ZX5GGwHtwiUNMghiVN02qACMAhKDxjvENNUYJFKiJAQGgEfisFLAwKzSMSAMTRhX3fZRP2-ZpYlcJAwEFNjB26bkwKGEt2LLSYWNw+RFBUdRZziUVZ1IwiGybfYW2VC5MK8DVZGCYo-iBA1IlQMUd2aPzGGnKAfOTDIvTnTSSQ0hcoHjNoAqzEk+2NU0BHNchqFJfjUE9Pjd0E4TZ2A-SxSFHLd1QGNyqFakbOlBssBY7BZ0TcIEuKXjj0vRhUBUsBvMS3KZwq1QKAAZWAJAqCoGIxwnCAWKBIEsWhEMYgEJAnF8VZH1CrqpwmLqzH66bBoNJLANGoVxqmma5t-RbltW9b9k27bduUfaPIRWrxu8YAeFWe7Zq3NaoBvGJLISH7PKvYKEVOgahvCK7bz7O7prBp6NyW3KVohqGoC2na9sPA6-tnAGgZB7HHtWmIjBAN7YQDWGKY8o7EaYIA). In there the third error still errors but the first two infers nicely.

### Additional information about the issue

_No response_

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza reproduciendo el ejemplo enlazado de Playground y compara los diagnósticos de las tres llamadas de configuración, especialmente el `silentNeverType` filtrado en las dos primeras. Rastrea las rutas de inferencia de tipos y de comprobación de relaciones de TypeScript implicadas; el trabajo estará terminado cuando las dos primeras llamadas infieran como se espera o informen de errores coherentes basados en `unknown` sin exponer `never`.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
compilers
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.