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(core): fix casting symbol values to strings in the prop type check warning #10729

Closed
wants to merge 2 commits into from

Conversation

jansiegel
Copy link

If the default value of the prop in the prop definition doesn't match the type of the prop, it should throw a warning, but instead it throws a TypeError when the default value is defined as a Symbol, e.g.:

testProp: {
    type: Number,
    default: Symbol('foo')
};

expected: Invalid prop: type check failed for prop "testProp". Expected Number, got Symbol
currently: TypeError: Cannot convert a Symbol value to a number

This PR changes the symbol->string casting from "" + value to String(value), as the first approach doesn't work well with symbols.
Also, I've added an isSymbol check, so it doesn't try to read the "value" of the symbol in the message warning + tests.

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

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

…k warning

- fix the TypeError being thrown instead of a prop type check warning in case of passing a symbol as the the prop's default value
- add prop type check warning test cases for symbols
@posva
Copy link
Member

posva commented Oct 18, 2019

Thank you but there is already #10529

@posva posva closed this Oct 18, 2019
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.

None yet

2 participants