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

Not able to infer parameter type in a function (Due to: input parameter order) #48719

Closed
mfleungac opened this issue Apr 15, 2022 · 2 comments
Closed
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@mfleungac
Copy link

Bug Report

🔎 Search Terms

infer function unknown

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

Checked #48538, not sure if related.
Tested with nightly build v4.7.0-dev.20220415, which should have fixed #48538, still not bugged.

⏯ Playground Link

[Playground link with relevant code
](https://www.typescriptlang.org/play?ts=4.7.0-dev.20220415#code/JYOwLgpgTgZghgYwgAgApQPYAcDOAeAETjDgBpkAlCEAE2gD5kBvAKGWRuLgC5kiSA3G2QQAHmCiIwvABScSvfnACUyALyMqtaEPZRqdKAElIAW1nAzvLYdUbkIAK4AbZ0IC+LFjEcgEYYAwQZEgcMEIuckoDBmQZAH0sTFxedGx8JXIbBlVWPQgwRyhgp1cPL1CwGTyOLl4AbQBGUgAmUgBmUgAWAF1SYX1tYytkYHVGJmQAeinkABUAC2AcUZXfAGsQDAB3EGF8wuKHFzdhd372MQkpWX0cO0Y7+oAGPpZ3ZSEvGeQAWn--sgAEYQZw7VbIbYYKDrUAAcz+AIBXlAkFgiBQaVwLQiJCyMSgE2EV0k-lk8h4fC4D2iQ10yEGhhMEHMcUsLOsBJppVOnm8vn8gWClRxmXY2UJcUSyRwqRlositMM9FyAwKRRKJ3KLBF1TVQ2ZrLG9kmP0WywhTlMIKg+wZ6qOPPp52J4lJ0jiNOa70+XiAA)](https://www.typescriptlang.org/play?ts=4.7.0-dev.20220415&ssl=37&ssc=1&pln=1&pc=1#code/JYOwLgpgTgZghgYwgAgApQPYAcDOAeAETjDgBpkAlCEAE2gD5kBvAKGWRuLgC5kiSA3G2QQAHmCiIwvABScSvfnACUyALyMqtaEPZRqdKAElIAW1nAzvLYdUbkIAK4AbZ0IC+LFjEcgEYYAwQZBgQQi5ySgMGZBkAfSxMXF50bHwlchsGVVY9CDBHKGCnVw8vUJlcji5eAG0ARlIAJlIAZlIAFgBdUmF9bWMrZGB1RiZkAHoJ5AAVAAtgHGGl3wBrEAwAdxBhPIKihxc3YXde9jEJKVl9HDtGG9qABh6Wd2UhLynkAFpf3+QAEYQZxbZbITYYKCrUAAcx+fz+XlAkFgiBQqVwTXCJEy0SgY2EF0k-lk8h4fC4dyiA10yH6hhMEHMsUsTOseKpJWOnm8vn8gWCoSxGXYWXxsQSSRwKSlwoi1MM9ByfXyhWKRzK3hATUqKoGjOZI3s4y+80WYKcpiBUF2dNVBy5tNOhPExOksSpjVe7y8QA)

💻 Code

interface Props<Data, Render> {
  data: Data;
  extract: (data: Data) => Render;
  renderItem: (item: Render) => null;
}

function fn<Data,  Render> (_props: Props<Data, Render>) {
  return null;
}

fn({
  data: [1,2,3,4],
  renderItem: i => { // This is unknown
    return null;
  },
  extract: (res) => res[0],
});


// ----- below is working -------

interface Props2<Data, Render> {
  extract: (data: Data) => Render;
  renderItem: (item: Render) => null;
}

function fn2<Data,  Render> (_props: Props2<Data, Render>) {
  return null;
}

fn2({
  renderItem: i => { // This is number
    return null;
  },
  extract: () => 1,
});

🙁 Actual behavior

in function fn1, parameter -> renderItem(i), " i " is inferred as unknown

🙂 Expected behavior

in function fn1, parameter -> renderItem(i), " i " should be inferred as number, as in fn2

@RyanCavanaugh RyanCavanaugh added the Design Limitation Constraints of the existing architecture prevent this from being fixed label Apr 15, 2022
@RyanCavanaugh
Copy link
Member

This logic is still order-sensitive; extract must come before renderItem for this to work

@mfleungac
Copy link
Author

I see @RyanCavanaugh Many Thanks

@mfleungac mfleungac changed the title Not able to infer parameter type in a function thats inside a function param Not able to infer parameter type in a function (Due to: input parameter order) Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

2 participants