fix(compile-sfc): add symbol judge in prop type checks. (#4594)

fix #4592
This commit is contained in:
ygj6 2021-09-17 01:45:55 +08:00 committed by GitHub
parent 06c5bf53ab
commit fcd5422b4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 0 deletions

View File

@ -971,6 +971,7 @@ export default /*#__PURE__*/_defineComponent({
interface: { type: Object, required: true }, interface: { type: Object, required: true },
alias: { type: Array, required: true }, alias: { type: Array, required: true },
method: { type: Function, required: true }, method: { type: Function, required: true },
symbol: { type: Symbol, required: true },
union: { type: [String, Number], required: true }, union: { type: [String, Number], required: true },
literalUnion: { type: String, required: true }, literalUnion: { type: String, required: true },
literalUnionNumber: { type: Number, required: true }, literalUnionNumber: { type: Number, required: true },

View File

@ -706,6 +706,7 @@ const emit = defineEmits(['a', 'b'])
interface: Test interface: Test
alias: Alias alias: Alias
method(): void method(): void
symbol: symbol
union: string | number union: string | number
literalUnion: 'foo' | 'bar' literalUnion: 'foo' | 'bar'
@ -735,6 +736,7 @@ const emit = defineEmits(['a', 'b'])
expect(content).toMatch(`interface: { type: Object, required: true }`) expect(content).toMatch(`interface: { type: Object, required: true }`)
expect(content).toMatch(`alias: { type: Array, required: true }`) expect(content).toMatch(`alias: { type: Array, required: true }`)
expect(content).toMatch(`method: { type: Function, required: true }`) expect(content).toMatch(`method: { type: Function, required: true }`)
expect(content).toMatch(`symbol: { type: Symbol, required: true }`)
expect(content).toMatch( expect(content).toMatch(
`union: { type: [String, Number], required: true }` `union: { type: [String, Number], required: true }`
) )
@ -767,6 +769,7 @@ const emit = defineEmits(['a', 'b'])
interface: BindingTypes.PROPS, interface: BindingTypes.PROPS,
alias: BindingTypes.PROPS, alias: BindingTypes.PROPS,
method: BindingTypes.PROPS, method: BindingTypes.PROPS,
symbol: BindingTypes.PROPS,
union: BindingTypes.PROPS, union: BindingTypes.PROPS,
literalUnion: BindingTypes.PROPS, literalUnion: BindingTypes.PROPS,
literalUnionNumber: BindingTypes.PROPS, literalUnionNumber: BindingTypes.PROPS,

View File

@ -1541,6 +1541,9 @@ function inferRuntimeType(
case 'TSIntersectionType': case 'TSIntersectionType':
return ['Object'] return ['Object']
case 'TSSymbolKeyword':
return ['Symbol']
default: default:
return [`null`] // no runtime check return [`null`] // no runtime check
} }