Microsoft/TypeScript

Missing errors in generic functions in context-sensitive arguments

Open

#61.979 aberto em 30 de jun. de 2025

Ver no GitHub
 (0 comments) (0 reactions) (0 assignees)TypeScript (6.726 forks)batch import
BugDomain: check: Contextual TypesHelp Wanted

Métricas do repositório

Stars
 (48.455 stars)
Métricas de merge de PR
 (Mesclagem média 6d 17h) (9 fundiu PRs em 30d)

Description

🔎 Search Terms

error generic type parameter inferred context senstivie contextual parameter

🕗 Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250627#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVNQB4AFAPgAow9EsBzALngG8AoeeMKCCAIyjADWjcgAdYUALYBnRsQCU8ALyl4lPBhAAPDI1TIJPEDAA08MTEkz48pSr0GjAbjbw0caBuAB+YbAbwpDBgsVFoFZXgANxwsYGcAXzlhc0tZcLt9QxhnFi0RHBgMDjxA+DgpZAgixQJyVnZObj5BRkIAFWMKFOlGNvTmF3Y4DGQYfHIoRh4cHAgQKFRTHn6J+C94AEZ4RgAGOUd4AHpD+AwACywpALOcSuB4IxgCgJwJEAB3M6MQJZm5hfgAEJFDV7FkXPFjC43CAPCBgMIAPr9JiQliJZxAA

💻 Code

declare function fn<P>(config: {
  callback: (params: P) => (context: number, params: P) => number;
  unrelated?: (arg: string) => void;
}): (params: P) => number;

export const result = fn({
  callback: <T,>(params: T) => {
    return (a: boolean, b) => (a ? 1 : 0); // this should error somewhere, boolean !== number
  },
  unrelated: (_) => {},
});

🙁 Actual behavior

No error

🙂 Expected behavior

It should error

Additional information about the issue

By hovering => we can see function<T>(params: T): {}. This indicates anyFunctionType leaked into .resolvedReturnType of that signature.

Guia do colaborador