Skip to content

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.

2 participants