Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken Autocomplete and Type Display For Parameters Dependent on Transitively Contextually Typed Return Type #61500

Open
LukeAbby opened this issue Mar 28, 2025 · 1 comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@LukeAbby
Copy link

LukeAbby commented Mar 28, 2025

πŸ”Ž Search Terms

contextually typed autocomplete, contextually typed type display, contextual return type

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ

⏯ Playground Link

https://www.typescriptlang.org/play/?ssl=2&ssc=13&pln=3&pc=3#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwFsoBrEAJRAEdkQBnDAHgCh54BFGmATwAVYoCTAHwAKFvADmIDADFUALngjIWEKgyKA3vAAOMHDsWpkBAEYgY8AL4BKeAF4h7Tr34EANOJ1vaigHI4AJKoiBYMHBauMAJCnjaKAG44WMAA3ExMAPSZ8AASOAkWWKgS8AUW8AAGRKQU1HQYlfC0ABY4AO608BgtUBhVEdx80QRNWF3FoTBwwPBQXZVoxKgdqE1QqLOV3iO0Y104pvRqtFimEFzdXDogs-NVSyvta-DtLVhgLfDj3+h4EjBkDhkF12lget13l0wFAIBBvl0NvALPoYAA6Jg1chUGj0MSsVjKCCqdR2RzwFRqDCeAnwbLwACqpxKc2QGBwYBwBB0EGkCBaFgQtGQEik9C6K10+huMAwl1IXFoGNpmisnnpAD14ABBGASExUsqIK43eAAclVZoR8BW-XmpwkqCg5wQ7N0bj5lhwxrlpotUoMRhM5hgqWsZoxNnSmJI2PqePEhMp6i0AcMNuDFVsDicyepibpOSZxVKUDZHK5PL58AFcBtHWaIrFGC6CqVBdVcVSQA

πŸ’» Code

declare function makeRequest<
  QueryParam
>(
  getFn: (client: { prop: number }) => QueryParam,
  params: NoInfer<QueryParam>,
): void;

// Hovering over `makeRequest` shows that `QueryParam` is inferred as `unknown` and `params` is obstensibly typed as `unknown` which is incongruous with this call is an error.
makeRequest(
    (client) => client,
    {},  // Using autocomplete in the object suggests no property keys.
// ^ Argument of type '{}' is not assignable to parameter of type '{ prop: number; }'.
);

makeRequest(
    (client: { prop: number }) => client,
    {}, // Using autocomplete here now suggests keys.
);

πŸ™ Actual behavior

The first call to makeRequest where client is contextually typed has broken autocomplete. No relevant properties are suggested. Furthermore hovering over makeRequest shows, incongruously, that params: unknown and yet the call {} causes an error expecting it to be of type { prop: number; }

πŸ™‚ Expected behavior

I expected auto-complete to work in all cases and the type display to be consistent.

Additional information about the issue

Related to #46916 but @Andarist hypothesized that the underlying root cause is different in this case so I decided to open it as its own issue for tracking purposes.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Mar 28, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 28, 2025
@Arya-A-Nair
Copy link

@RyanCavanaugh would like to work on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants