1.0.26
https://jsbin.com/sozesub/10/edit?html,js,console,output
Create a component with a prop with both a "type" and "default" value.
When an invalid type is passed, undefined is set for value rather than the default.
Feels like props should remain with default values when improper data is passed when they are "type" restricted.
I would say that this behaviour is intentional and rightly so.
While it may seem to you, the developer, be practical to prevent errors from invalid types by overriding them with a default, it will/can lead to stange behaviour for users - "the app does not show any errors, but somehow the value X simply changed" etc..
If it's undefined, you have the possibility (and responsibility) to handle the error in the component explicitly (_'oops, something went wrong'_) with a simple if (this.prop === undefined)
Does that make sense to you?
Feels like this should be denoted in docs as undefined here is really of an error. I swapped back to debugging version and error was shown in console for invalid props.
Thanks
Most helpful comment
I would say that this behaviour is intentional and rightly so.
While it may seem to you, the developer, be practical to prevent errors from invalid types by overriding them with a default, it will/can lead to stange behaviour for users - "the app does not show any errors, but somehow the value X simply changed" etc..
If it's
undefined, you have the possibility (and responsibility) to handle the error in the component explicitly (_'oops, something went wrong'_) with a simpleif (this.prop === undefined)Does that make sense to you?