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

fix: avoid including Function type in inferred props type #301

Closed
wants to merge 1 commit into from

Conversation

ktsn
Copy link
Member

@ktsn ktsn commented Apr 2, 2020

fix #291

The issue was caused by distribution of conditional types. The reason there is no issue when we declare props type via { type: String } format is T extends { type: PropType<infer V, boolean> } won't be distributed.

The solution is just avoiding distribution in the conditional types in InferPropType. To do that, I wrapped all conditional types with tuple.

@@ -105,6 +112,24 @@ describe('defineComponent', () => {
expect.assertions(3);
});

it('custom props type inferred from PropType', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is passing on master branch 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is because the behavior prior TS 3.9 because PropsType includes {} type which can be assigned to { user?: User }. 🤔

https://devblogs.microsoft.com/typescript/announcing-typescript-3-9-rc/

Generally, an intersection type like A & B is assignable to C if either A or B is assignable to C

Once I updated TS to 3.9, the test fails on master.

@antfu antfu mentioned this pull request Jun 3, 2020
@pikax
Copy link
Member

pikax commented Jun 7, 2020

@antfu can we get this merged before release of 0.6.0?

Bug is still in master:

interface A {
  a: String
}

defineComponent({
  props: {
    a: Object as PropType<A>
  },
  setup(props){
    props.a
  }
})

@antfu
Copy link
Member

antfu commented Jun 7, 2020

This does not seems to fix for me:

image
image

Meanwhile, vue-next does not use this hack while solving the issue. I guess we need to rework the props typing to align with vue-next instead. And since the release has been delayed for too long, my plan would be delivering the release first and delay this PR into the next release so we can have more time to better take care of it.

@antfu
Copy link
Member

antfu commented Jun 7, 2020

Closing this in favor of #352. Thanks.

@antfu antfu closed this Jun 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript: 'Function' type of PropType introduced in 0.5.0 is annoying when using Vetur
3 participants