Microsoft/TypeScript

Missing errors in generic functions in context-sensitive arguments

Open

#61,979 opened on Jun 30, 2025

View on GitHub
 (0 comments) (0 reactions) (0 assignees)TypeScript (48,455 stars) (6,726 forks)batch import
BugDomain: check: Contextual TypesHelp Wanted

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.

Contributor guide