mirror of https://github.com/vuejs/core.git
fix(compiler-sfc): infer function prop type from type literal w/ callable signature (#7119)
This commit is contained in:
parent
701b95ff3d
commit
3a7572cdb2
|
@ -1619,6 +1619,7 @@ export default /*#__PURE__*/_defineComponent({
|
||||||
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 },
|
symbol: { type: Symbol, required: true },
|
||||||
|
objectOrFn: { type: [Function, Object], 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 },
|
||||||
|
|
|
@ -960,6 +960,10 @@ const emit = defineEmits(['a', 'b'])
|
||||||
alias: Alias
|
alias: Alias
|
||||||
method(): void
|
method(): void
|
||||||
symbol: symbol
|
symbol: symbol
|
||||||
|
objectOrFn: {
|
||||||
|
(): void
|
||||||
|
foo: string
|
||||||
|
}
|
||||||
|
|
||||||
union: string | number
|
union: string | number
|
||||||
literalUnion: 'foo' | 'bar'
|
literalUnion: 'foo' | 'bar'
|
||||||
|
@ -990,6 +994,9 @@ const emit = defineEmits(['a', 'b'])
|
||||||
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(`symbol: { type: Symbol, required: true }`)
|
||||||
|
expect(content).toMatch(
|
||||||
|
`objectOrFn: { type: [Function, Object], required: true },`
|
||||||
|
)
|
||||||
expect(content).toMatch(
|
expect(content).toMatch(
|
||||||
`union: { type: [String, Number], required: true }`
|
`union: { type: [String, Number], required: true }`
|
||||||
)
|
)
|
||||||
|
@ -1023,6 +1030,7 @@ const emit = defineEmits(['a', 'b'])
|
||||||
alias: BindingTypes.PROPS,
|
alias: BindingTypes.PROPS,
|
||||||
method: BindingTypes.PROPS,
|
method: BindingTypes.PROPS,
|
||||||
symbol: BindingTypes.PROPS,
|
symbol: BindingTypes.PROPS,
|
||||||
|
objectOrFn: BindingTypes.PROPS,
|
||||||
union: BindingTypes.PROPS,
|
union: BindingTypes.PROPS,
|
||||||
literalUnion: BindingTypes.PROPS,
|
literalUnion: BindingTypes.PROPS,
|
||||||
literalUnionNumber: BindingTypes.PROPS,
|
literalUnionNumber: BindingTypes.PROPS,
|
||||||
|
|
|
@ -2001,9 +2001,21 @@ function inferRuntimeType(
|
||||||
return ['Boolean']
|
return ['Boolean']
|
||||||
case 'TSObjectKeyword':
|
case 'TSObjectKeyword':
|
||||||
return ['Object']
|
return ['Object']
|
||||||
case 'TSTypeLiteral':
|
case 'TSTypeLiteral': {
|
||||||
// TODO (nice to have) generate runtime property validation
|
// TODO (nice to have) generate runtime property validation
|
||||||
return ['Object']
|
const types = new Set<string>()
|
||||||
|
for (const m of node.members) {
|
||||||
|
switch (m.type) {
|
||||||
|
case 'TSCallSignatureDeclaration':
|
||||||
|
case 'TSConstructSignatureDeclaration':
|
||||||
|
types.add('Function')
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
types.add('Object')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Array.from(types)
|
||||||
|
}
|
||||||
case 'TSFunctionType':
|
case 'TSFunctionType':
|
||||||
return ['Function']
|
return ['Function']
|
||||||
case 'TSArrayType':
|
case 'TSArrayType':
|
||||||
|
|
Loading…
Reference in New Issue