fix(types): incorrect type inference of array (#4578)
This commit is contained in:
parent
58b1fa5ed1
commit
140f089917
@ -41,7 +41,11 @@ export type DefineComponent<
|
|||||||
E extends EmitsOptions = {},
|
E extends EmitsOptions = {},
|
||||||
EE extends string = string,
|
EE extends string = string,
|
||||||
PP = PublicProps,
|
PP = PublicProps,
|
||||||
Props = Readonly<ExtractPropTypes<PropsOrPropOptions>> &
|
Props = Readonly<
|
||||||
|
PropsOrPropOptions extends ComponentPropsOptions
|
||||||
|
? ExtractPropTypes<PropsOrPropOptions>
|
||||||
|
: PropsOrPropOptions
|
||||||
|
> &
|
||||||
({} extends E ? {} : EmitsToProps<E>),
|
({} extends E ? {} : EmitsToProps<E>),
|
||||||
Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>
|
Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>
|
||||||
> = ComponentPublicInstanceConstructor<
|
> = ComponentPublicInstanceConstructor<
|
||||||
|
@ -333,35 +333,31 @@ describe('with object props', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// describe('type inference w/ optional props declaration', () => {
|
describe('type inference w/ optional props declaration', () => {
|
||||||
// const MyComponent = defineComponent({
|
const MyComponent = defineComponent<{ a: string[]; msg: string }>({
|
||||||
// setup(_props: { msg: string }) {
|
setup(props) {
|
||||||
// return {
|
expectType<string>(props.msg)
|
||||||
// a: 1
|
expectType<string[]>(props.a)
|
||||||
// }
|
return {
|
||||||
// },
|
b: 1
|
||||||
// render() {
|
}
|
||||||
// expectType<string>(this.$props.msg)
|
}
|
||||||
// // props should be readonly
|
})
|
||||||
// expectError((this.$props.msg = 'foo'))
|
|
||||||
// // should not expose on `this`
|
|
||||||
// expectError(this.msg)
|
|
||||||
// expectType<number>(this.a)
|
|
||||||
// return null
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
// expectType<JSX.Element>(<MyComponent msg="foo" />)
|
expectType<JSX.Element>(<MyComponent msg="1" a={['1']} />)
|
||||||
// expectError(<MyComponent />)
|
// @ts-expect-error
|
||||||
// expectError(<MyComponent msg={1} />)
|
expectError(<MyComponent />)
|
||||||
// })
|
// @ts-expect-error
|
||||||
|
expectError(<MyComponent msg="1" />)
|
||||||
|
})
|
||||||
|
|
||||||
// describe('type inference w/ direct setup function', () => {
|
describe('type inference w/ direct setup function', () => {
|
||||||
// const MyComponent = defineComponent((_props: { msg: string }) => {})
|
const MyComponent = defineComponent((_props: { msg: string }) => {})
|
||||||
// expectType<JSX.Element>(<MyComponent msg="foo" />)
|
expectType<JSX.Element>(<MyComponent msg="foo" />)
|
||||||
// expectError(<MyComponent />)
|
// @ts-expect-error
|
||||||
// expectError(<MyComponent msg={1} />)
|
expectError(<MyComponent />)
|
||||||
// })
|
expectError(<MyComponent msg="1" />)
|
||||||
|
})
|
||||||
|
|
||||||
describe('type inference w/ array props declaration', () => {
|
describe('type inference w/ array props declaration', () => {
|
||||||
const MyComponent = defineComponent({
|
const MyComponent = defineComponent({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user