typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

Broken property suggestions due to a successfully contextually typed function

Open LukeAbby opened this issue 3 weeks ago • 0 comments

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 here suggests globals, not `prop` like it should.
    {},
// ^ Argument of type '{}' is not assignable to parameter of type '{ prop: number; }'.
);

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

Sub-part of https://github.com/microsoft/TypeScript/issues/46916#issuecomment-2759515773 with parts pointed out with https://github.com/microsoft/TypeScript/issues/46916#issuecomment-2760441648

See @Andarist's analysis at https://github.com/microsoft/TypeScript/issues/46916#issuecomment-2760441648

LukeAbby avatar Dec 03 '25 07:12 LukeAbby