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

types(withDefaults): improve the type of boolean attribute value #8602

Merged
merged 2 commits into from Jul 11, 2023

Conversation

zqran
Copy link
Contributor

@zqran zqran commented Jun 19, 2023

Before:

const props = withDefaults(defineProps<{ active?: boolean }>(), {
  active: undefined
})
props.active // boolean
props.active.toString() // error!

After:

const props = withDefaults(defineProps<{ active?: boolean }>(), {})
props.active // boolean

const props = withDefaults(defineProps<{ active?: boolean }>(), {
  active: undefined
})
props.active // boolean | undefined

Also matches the following usages:

export default defineComponent({
  props: {
    active: {
      type: Boolean,
      required: false,
      default: undefined
    }
  },

  setup(props) {
    props.active // boolean | undefined
  }
})

Related to: #8576

@rxliuli
Copy link

rxliuli commented Jul 11, 2023

Where is it blocked now? Why not merge it?

@zqran
Copy link
Contributor Author

zqran commented Jul 11, 2023

Where is it blocked now? Why not merge it?

There are no members to review this PR yet, maybe you can @ some members to take a look.

@sxzz sxzz added the ready to merge The PR is ready to be merged. label Jul 11, 2023
@yyx990803 yyx990803 merged commit f07cb18 into vuejs:main Jul 11, 2023
11 checks passed
@zqran zqran deleted the 0619-with-defaults-type branch July 11, 2023 13:32
zhangenming added a commit to zhangenming/vue-next that referenced this pull request Jul 11, 2023
… with undefined default value (vuejs#8602)"

This reverts commit f07cb18.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge The PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants