refactor(types): widen Component type to include consutructor types
returned from `defineComponent` ref: https://github.com/vuejs/vue-router-next/pull/421 also close #1880 Previous `Component` type is now exported as `ConcreteComponent`. This introduces a minor breaking change when calling `h(comp, { ... })` will now fail if `comp` is a of generic `Component` type, since it does not specify what props it expects.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
describe,
|
||||
Component,
|
||||
defineComponent,
|
||||
PropType,
|
||||
ref,
|
||||
@@ -179,6 +180,8 @@ describe('with object props', () => {
|
||||
}
|
||||
})
|
||||
|
||||
expectType<Component>(MyComponent)
|
||||
|
||||
// Test TSX
|
||||
expectType<JSX.Element>(
|
||||
<MyComponent
|
||||
@@ -205,6 +208,17 @@ describe('with object props', () => {
|
||||
/>
|
||||
)
|
||||
|
||||
expectType<Component>(
|
||||
<MyComponent
|
||||
b="b"
|
||||
dd={{ n: 1 }}
|
||||
ddd={['ddd']}
|
||||
eee={() => ({ a: 'eee' })}
|
||||
fff={(a, b) => ({ a: a > +b })}
|
||||
hhh={false}
|
||||
/>
|
||||
)
|
||||
|
||||
// @ts-expect-error missing required props
|
||||
expectError(<MyComponent />)
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ describe('h inference w/ Fragment', () => {
|
||||
// only accepts array children
|
||||
h(Fragment, ['hello'])
|
||||
h(Fragment, { key: 123 }, ['hello'])
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error
|
||||
expectError(h(Fragment, 'foo'))
|
||||
// @ts-expect-error
|
||||
expectError(h(Fragment, { key: 123 }, 'bar'))
|
||||
@@ -46,11 +46,11 @@ describe('h inference w/ Fragment', () => {
|
||||
|
||||
describe('h inference w/ Teleport', () => {
|
||||
h(Teleport, { to: '#foo' }, 'hello')
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error
|
||||
expectError(h(Teleport))
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error
|
||||
expectError(h(Teleport, {}))
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error
|
||||
expectError(h(Teleport, { to: '#foo' }))
|
||||
})
|
||||
|
||||
@@ -148,6 +148,7 @@ describe('h support for generic component type', () => {
|
||||
function foo(bar: Component) {
|
||||
h(bar)
|
||||
h(bar, 'hello')
|
||||
// @ts-expect-error
|
||||
h(bar, { id: 'ok' }, 'hello')
|
||||
}
|
||||
foo({})
|
||||
|
||||
Reference in New Issue
Block a user