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

Contextual typing breaks with partially applied type arguments #43524

Closed
myandrienko opened this issue Apr 4, 2021 · 2 comments
Closed

Contextual typing breaks with partially applied type arguments #43524

myandrienko opened this issue Apr 4, 2021 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@myandrienko
Copy link

myandrienko commented Apr 4, 2021

Bug Report

πŸ”Ž Search Terms

partial type argument inference, contextual typing

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about type inference

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

interface Props<TSchema, TValue> {
  getter: (values: TSchema) => TValue;
  worker: (value: TValue) => void;
}

declare function fn<TSchema, TValue>(props: Props<TSchema, TValue>): void;

function bindSchema<TSchema>() {
  return function boundFn<TValue>(props: Props<TSchema, TValue>) {
    fn(props);
  };
}

const boundFn = bindSchema<{ someValue: number }>();

boundFn({
  getter: (values) => values.someValue,
  worker: (value) => {
    // value is unknown :(
  }
});

πŸ™ Actual behavior

value parameter type in worker method (line 18). is not inferred. value type is unknown.

πŸ™‚ Expected behavior

value parameter type should be correctly inferred as number.

This code sample works fine, which is also surprising since the type for values parameter in getter method (line 17) is correctly inferred as { someValue: number } anyway:

boundFn({
  getter: (values: { someValue: number }) => values.someValue,
  worker: (value) => {
    // value is number πŸ‘ 
  }
});
@ilogico
Copy link

ilogico commented Apr 4, 2021

Looks like #43371

@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Apr 5, 2021
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants