mirror of https://github.com/vuejs/core.git
fix(compiler-sfc): handle readonly operator and ReadonlyArray/Map/Set types
close #10726
This commit is contained in:
parent
65109a70f1
commit
5cef52a5c2
|
@ -265,6 +265,27 @@ describe('resolveType', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('utility type: ReadonlyArray', () => {
|
||||||
|
expect(
|
||||||
|
resolve(`
|
||||||
|
defineProps<{ foo: ReadonlyArray<string> }>()
|
||||||
|
`).props,
|
||||||
|
).toStrictEqual({
|
||||||
|
foo: ['Array'],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('utility type: ReadonlyMap & Readonly Set', () => {
|
||||||
|
expect(
|
||||||
|
resolve(`
|
||||||
|
defineProps<{ foo: ReadonlyMap<string, unknown>, bar: ReadonlySet<string> }>()
|
||||||
|
`).props,
|
||||||
|
).toStrictEqual({
|
||||||
|
foo: ['Map'],
|
||||||
|
bar: ['Set'],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test('indexed access type (literal)', () => {
|
test('indexed access type (literal)', () => {
|
||||||
expect(
|
expect(
|
||||||
resolve(`
|
resolve(`
|
||||||
|
@ -416,6 +437,16 @@ describe('resolveType', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('readonly', () => {
|
||||||
|
expect(
|
||||||
|
resolve(`
|
||||||
|
defineProps<{ foo: readonly unknown[] }>()
|
||||||
|
`).props,
|
||||||
|
).toStrictEqual({
|
||||||
|
foo: ['Array'],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test('ExtractPropTypes (element-plus)', () => {
|
test('ExtractPropTypes (element-plus)', () => {
|
||||||
const { props, raw } = resolve(
|
const { props, raw } = resolve(
|
||||||
`
|
`
|
||||||
|
|
|
@ -1547,8 +1547,14 @@ export function inferRuntimeType(
|
||||||
|
|
||||||
case 'Parameters':
|
case 'Parameters':
|
||||||
case 'ConstructorParameters':
|
case 'ConstructorParameters':
|
||||||
|
case 'ReadonlyArray':
|
||||||
return ['Array']
|
return ['Array']
|
||||||
|
|
||||||
|
case 'ReadonlyMap':
|
||||||
|
return ['Map']
|
||||||
|
case 'ReadonlySet':
|
||||||
|
return ['Set']
|
||||||
|
|
||||||
case 'NonNullable':
|
case 'NonNullable':
|
||||||
if (node.typeParameters && node.typeParameters.params[0]) {
|
if (node.typeParameters && node.typeParameters.params[0]) {
|
||||||
return inferRuntimeType(
|
return inferRuntimeType(
|
||||||
|
@ -1633,6 +1639,11 @@ export function inferRuntimeType(
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// e.g. readonly
|
||||||
|
case 'TSTypeOperator': {
|
||||||
|
return inferRuntimeType(ctx, node.typeAnnotation, scope)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// always soft fail on failed runtime type inference
|
// always soft fail on failed runtime type inference
|
||||||
|
|
Loading…
Reference in New Issue