fix(types): ensure correct public props interface for defineComponent instance type
fix #1385
This commit is contained in:
parent
8904dec00b
commit
2961e149c9
@ -174,7 +174,7 @@ export function defineComponent<
|
|||||||
>
|
>
|
||||||
): ComponentPublicInstanceConstructor<
|
): ComponentPublicInstanceConstructor<
|
||||||
CreateComponentPublicInstance<
|
CreateComponentPublicInstance<
|
||||||
ExtractPropTypes<PropsOptions>,
|
ExtractPropTypes<PropsOptions, false>,
|
||||||
RawBindings,
|
RawBindings,
|
||||||
D,
|
D,
|
||||||
C,
|
C,
|
||||||
@ -182,7 +182,7 @@ export function defineComponent<
|
|||||||
Mixin,
|
Mixin,
|
||||||
Extends,
|
Extends,
|
||||||
E,
|
E,
|
||||||
VNodeProps & ExtractPropTypes<PropsOptions, false>
|
VNodeProps
|
||||||
>
|
>
|
||||||
> &
|
> &
|
||||||
ComponentOptionsWithObjectProps<
|
ComponentOptionsWithObjectProps<
|
||||||
|
@ -22,7 +22,7 @@ describe('h inference w/ element', () => {
|
|||||||
// ref
|
// ref
|
||||||
h('div', { ref: 'foo' })
|
h('div', { ref: 'foo' })
|
||||||
h('div', { ref: ref(null) })
|
h('div', { ref: ref(null) })
|
||||||
h('div', { ref: el => {} })
|
h('div', { ref: _el => {} })
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
expectError(h('div', { ref: [] }))
|
expectError(h('div', { ref: [] }))
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
@ -111,37 +111,37 @@ describe('h inference w/ defineComponent', () => {
|
|||||||
expectError(h(Foo, { bar: 1, foo: 1 }))
|
expectError(h(Foo, { bar: 1, foo: 1 }))
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('h inference w/ defineComponent + optional props', () => {
|
// describe('h inference w/ defineComponent + optional props', () => {
|
||||||
const Foo = defineComponent({
|
// const Foo = defineComponent({
|
||||||
setup(_props: { foo?: string; bar: number }) {}
|
// setup(_props: { foo?: string; bar: number }) {}
|
||||||
})
|
// })
|
||||||
|
|
||||||
h(Foo, { bar: 1 })
|
// h(Foo, { bar: 1 })
|
||||||
h(Foo, { bar: 1, foo: 'ok' })
|
// h(Foo, { bar: 1, foo: 'ok' })
|
||||||
// should allow extraneous props (attrs fallthrough)
|
// // should allow extraneous props (attrs fallthrough)
|
||||||
h(Foo, { bar: 1, foo: 'ok', class: 'extra' })
|
// h(Foo, { bar: 1, foo: 'ok', class: 'extra' })
|
||||||
// @ts-expect-error should fail on missing required prop
|
// // @ts-expect-error should fail on missing required prop
|
||||||
expectError(h(Foo, {}))
|
// expectError(h(Foo, {}))
|
||||||
// @ts-expect-error
|
// // @ts-expect-error
|
||||||
expectError(h(Foo, { foo: 'ok' }))
|
// expectError(h(Foo, { foo: 'ok' }))
|
||||||
// @ts-expect-error should fail on wrong type
|
// // @ts-expect-error should fail on wrong type
|
||||||
expectError(h(Foo, { bar: 1, foo: 1 }))
|
// expectError(h(Foo, { bar: 1, foo: 1 }))
|
||||||
})
|
// })
|
||||||
|
|
||||||
describe('h inference w/ defineComponent + direct function', () => {
|
// describe('h inference w/ defineComponent + direct function', () => {
|
||||||
const Foo = defineComponent((_props: { foo?: string; bar: number }) => {})
|
// const Foo = defineComponent((_props: { foo?: string; bar: number }) => {})
|
||||||
|
|
||||||
h(Foo, { bar: 1 })
|
// h(Foo, { bar: 1 })
|
||||||
h(Foo, { bar: 1, foo: 'ok' })
|
// h(Foo, { bar: 1, foo: 'ok' })
|
||||||
// should allow extraneous props (attrs fallthrough)
|
// // should allow extraneous props (attrs fallthrough)
|
||||||
h(Foo, { bar: 1, foo: 'ok', class: 'extra' })
|
// h(Foo, { bar: 1, foo: 'ok', class: 'extra' })
|
||||||
// @ts-expect-error should fail on missing required prop
|
// // @ts-expect-error should fail on missing required prop
|
||||||
expectError(h(Foo, {}))
|
// expectError(h(Foo, {}))
|
||||||
// @ts-expect-error
|
// // @ts-expect-error
|
||||||
expectError(h(Foo, { foo: 'ok' }))
|
// expectError(h(Foo, { foo: 'ok' }))
|
||||||
// @ts-expect-error should fail on wrong type
|
// // @ts-expect-error should fail on wrong type
|
||||||
expectError(h(Foo, { bar: 1, foo: 1 }))
|
// expectError(h(Foo, { bar: 1, foo: 1 }))
|
||||||
})
|
// })
|
||||||
|
|
||||||
// #922
|
// #922
|
||||||
describe('h support for generic component type', () => {
|
describe('h support for generic component type', () => {
|
||||||
@ -183,3 +183,17 @@ describe('describeComponent extends Component', () => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// #1385
|
||||||
|
describe('component w/ props w/ default value', () => {
|
||||||
|
const MyComponent = defineComponent({
|
||||||
|
props: {
|
||||||
|
message: {
|
||||||
|
type: String,
|
||||||
|
default: 'hello'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
h(MyComponent, {})
|
||||||
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user