Skip to content

Commit

Permalink
fix(compile-sfc): add symbol judge in prop type checks. (#4594)
Browse files Browse the repository at this point in the history
fix #4592
  • Loading branch information
ygj6 committed Sep 16, 2021
1 parent 06c5bf5 commit fcd5422
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
Expand Up @@ -971,6 +971,7 @@ export default /*#__PURE__*/_defineComponent({
interface: { type: Object, required: true },
alias: { type: Array, required: true },
method: { type: Function, required: true },
symbol: { type: Symbol, required: true },
union: { type: [String, Number], required: true },
literalUnion: { type: String, required: true },
literalUnionNumber: { type: Number, required: true },
Expand Down
3 changes: 3 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Expand Up @@ -706,6 +706,7 @@ const emit = defineEmits(['a', 'b'])
interface: Test
alias: Alias
method(): void
symbol: symbol
union: string | number
literalUnion: 'foo' | 'bar'
Expand Down Expand Up @@ -735,6 +736,7 @@ const emit = defineEmits(['a', 'b'])
expect(content).toMatch(`interface: { type: Object, required: true }`)
expect(content).toMatch(`alias: { type: Array, required: true }`)
expect(content).toMatch(`method: { type: Function, required: true }`)
expect(content).toMatch(`symbol: { type: Symbol, required: true }`)
expect(content).toMatch(
`union: { type: [String, Number], required: true }`
)
Expand Down Expand Up @@ -767,6 +769,7 @@ const emit = defineEmits(['a', 'b'])
interface: BindingTypes.PROPS,
alias: BindingTypes.PROPS,
method: BindingTypes.PROPS,
symbol: BindingTypes.PROPS,
union: BindingTypes.PROPS,
literalUnion: BindingTypes.PROPS,
literalUnionNumber: BindingTypes.PROPS,
Expand Down
3 changes: 3 additions & 0 deletions packages/compiler-sfc/src/compileScript.ts
Expand Up @@ -1541,6 +1541,9 @@ function inferRuntimeType(
case 'TSIntersectionType':
return ['Object']

case 'TSSymbolKeyword':
return ['Symbol']

default:
return [`null`] // no runtime check
}
Expand Down

0 comments on commit fcd5422

Please sign in to comment.