Skip to content

Contextual type inference fails in surprising case  #25814

Closed
@bterlson

Description

@bterlson

TypeScript Version: 3.1.0-dev.20180719
Code

type R = {
  a: (x: number) => void;
  b: (x: string) => void;
};

type O = {
  on<P extends keyof R>(x: P, callback: R[P]): void;
};

declare var x: O;
x.on('a', a => {}); // not contextually typed.

Expected behavior:
Contextually type a to number.

Actual behavior:
A is not contextually typed, while signature help gives the correct answer.

Playground Link: here

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixedFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions