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: defineComponent() with array props #364

Merged
merged 7 commits into from
Jun 10, 2020
Merged

Conversation

antfu
Copy link
Member

@antfu antfu commented Jun 9, 2020

This continues #150, as it's kinda out-of-date. The type declarations are ported from vue-next.

Before
image

After
image

@antfu
Copy link
Member Author

antfu commented Jun 9, 2020

Tests passed on my machine but failed on Github Actions. I guess it's because it uses npm without package-lock.json, which may cause dependencies inconsistency. Hold to see if the error still persists after #347 gets merged.

@antfu
Copy link
Member Author

antfu commented Jun 10, 2020

Passed with ts v3.9.4 but failed with the latest v3.9.5. Let's hold it for a while.

@pikax
Copy link
Member

pikax commented Jun 10, 2020

Updated to 3.9.5 on vue-next and no error, do you want me to fix this?

@antfu
Copy link
Member Author

antfu commented Jun 10, 2020

@pikax it's might due to that I have moved the array overload in front of the object one. And yes, it would be great if you can help out :)

@pikax
Copy link
Member

pikax commented Jun 10, 2020

Replace PropOptions with:

type DefaultFactory<T> = () => T | null | undefined;

interface PropOptions<T = any> {
  type?: PropType<T> | true | null;
  required?: boolean;
  default?: T | DefaultFactory<T> | null | undefined;
  validator?(value: unknown): boolean;
}

@antfu
Copy link
Member Author

antfu commented Jun 10, 2020

It works. Thanks!

@FloryanFilip
Copy link

Can I somehow define my prop as tuple value?
plannerDateRange: { type: Array as PropType<[string, string]>, required: true },
The above produces compilation error:
Screenshot 2021-01-19 at 14 29 28

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.

3 participants