Empty type name in warning when expected prop type is a custom class
Vue version
3.2.45
Link to minimal reproduction
Steps to reproduce
Juggle between passing the invalidPropType
and validPropType
to the component and observe the warning message
What is expected?
The warning message should contain the expected class' name
What is actually happening?
Warning message contains an empty string
System Info
No response
Any additional comments?
The issue comes from the getType
function ( https://github.com/vuejs/core/blob/54b6ba32cafcc41fa9b7b85f1f1a306923204177/packages/runtime-core/src/componentProps.ts#L560 ) attempting to match the toString()
result for a function
keyword. This fails for classes since they return a class [NAME] {}
when stringified. Couldn't we just use ctor.name
here? It returns Object
when passed an object, Array
when passed an array etc, I don't know if it's widely supported though
This happens when TS is not used and this method of defining props with custom classes is even referenced in Vue's guide to prop validation: https://vuejs.org/guide/components/props.html#runtime-type-checks
This function returns an empty string for custom classes because MyClass.toString()
does not match the regexp when using real native ES6 classes. Should be easy enough to extend this to also work for custom classes.