Skip to content

Broken property suggestions due to a successfully contextually typed function #2187

@LukeAbby

Description

@LukeAbby
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 microsoft/TypeScript#46916 (comment) with parts pointed out with microsoft/TypeScript#46916 (comment)

See @Andarist's analysis at microsoft/TypeScript#46916 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: EditorRelated to the LSP server, editor experience

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions