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(types): relax the return type of props default option #8537

Merged
merged 1 commit into from
Sep 18, 2018

Conversation

ktsn
Copy link
Member

@ktsn ktsn commented Jul 21, 2018

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

The PR fulfills these requirements:

Other information:

Currently, the return type of default option is annotated with object since it is used for generating fresh object for each component instance. But there is another use case for default option of function in portal-vue which is for dynamically generating unique value as default.
https://github.com/LinusBorg/portal-vue/blob/develop/src/components/portal.js#L16

The current typing breaks this type inference when the default function returns non-object type. I just relaxed the return type to any to avoid breaking the inference.

@ktsn ktsn requested a review from HerringtonDarkholme July 21, 2018 04:01
@ktsn ktsn force-pushed the relax-props-default-type branch from b35b1db to 8f2b516 Compare July 21, 2018 04:06
@ktsn
Copy link
Member Author

ktsn commented Jul 21, 2018

Maybe () => T | null | undefined is better instead of () => any?

@yyx990803 yyx990803 merged commit a9eb198 into vuejs:dev Sep 18, 2018
@ktsn ktsn deleted the relax-props-default-type branch September 18, 2018 08:02
@fjc0k
Copy link
Contributor

fjc0k commented Oct 17, 2018

thx!

let zIndex = 5000

export default Vue.extend({
  name: 'Popup',
  props: {
    zIndex: {
      type: Number,
      default: (): number => zIndex++
    }
  }
})

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.

4 participants