mirror of https://github.com/vuejs/core.git
fix(types): avoid merging component instance into `$props` in `ComponentInstance` (#12870)
close #12751
This commit is contained in:
parent
c69c4bb59c
commit
f44feed6fa
|
@ -137,3 +137,18 @@ describe('Generic component', () => {
|
||||||
expectType<string | number>(comp.msg)
|
expectType<string | number>(comp.msg)
|
||||||
expectType<Array<string | number>>(comp.list)
|
expectType<Array<string | number>>(comp.list)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// #12751
|
||||||
|
{
|
||||||
|
const Comp = defineComponent({
|
||||||
|
__typeEmits: {} as {
|
||||||
|
'update:visible': [value?: boolean]
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const comp: ComponentInstance<typeof Comp> = {} as any
|
||||||
|
|
||||||
|
expectType<((value?: boolean) => any) | undefined>(comp['onUpdate:visible'])
|
||||||
|
expectType<{ 'onUpdate:visible'?: (value?: boolean) => any }>(comp['$props'])
|
||||||
|
// @ts-expect-error
|
||||||
|
comp['$props']['$props']
|
||||||
|
}
|
||||||
|
|
|
@ -115,20 +115,23 @@ export type ComponentInstance<T> = T extends { new (): ComponentPublicInstance }
|
||||||
: T extends FunctionalComponent<infer Props, infer Emits>
|
: T extends FunctionalComponent<infer Props, infer Emits>
|
||||||
? ComponentPublicInstance<Props, {}, {}, {}, {}, ShortEmitsToObject<Emits>>
|
? ComponentPublicInstance<Props, {}, {}, {}, {}, ShortEmitsToObject<Emits>>
|
||||||
: T extends Component<
|
: T extends Component<
|
||||||
infer Props,
|
infer PropsOrInstance,
|
||||||
infer RawBindings,
|
infer RawBindings,
|
||||||
infer D,
|
infer D,
|
||||||
infer C,
|
infer C,
|
||||||
infer M
|
infer M
|
||||||
>
|
>
|
||||||
? // NOTE we override Props/RawBindings/D to make sure is not `unknown`
|
? PropsOrInstance extends { $props: unknown }
|
||||||
ComponentPublicInstance<
|
? // T is returned by `defineComponent()`
|
||||||
unknown extends Props ? {} : Props,
|
PropsOrInstance
|
||||||
unknown extends RawBindings ? {} : RawBindings,
|
: // NOTE we override Props/RawBindings/D to make sure is not `unknown`
|
||||||
unknown extends D ? {} : D,
|
ComponentPublicInstance<
|
||||||
C,
|
unknown extends PropsOrInstance ? {} : PropsOrInstance,
|
||||||
M
|
unknown extends RawBindings ? {} : RawBindings,
|
||||||
>
|
unknown extends D ? {} : D,
|
||||||
|
C,
|
||||||
|
M
|
||||||
|
>
|
||||||
: never // not a vue Component
|
: never // not a vue Component
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -259,7 +262,7 @@ export type ConcreteComponent<
|
||||||
* The constructor type is an artificial type returned by defineComponent().
|
* The constructor type is an artificial type returned by defineComponent().
|
||||||
*/
|
*/
|
||||||
export type Component<
|
export type Component<
|
||||||
Props = any,
|
PropsOrInstance = any,
|
||||||
RawBindings = any,
|
RawBindings = any,
|
||||||
D = any,
|
D = any,
|
||||||
C extends ComputedOptions = ComputedOptions,
|
C extends ComputedOptions = ComputedOptions,
|
||||||
|
@ -267,8 +270,8 @@ export type Component<
|
||||||
E extends EmitsOptions | Record<string, any[]> = {},
|
E extends EmitsOptions | Record<string, any[]> = {},
|
||||||
S extends Record<string, any> = any,
|
S extends Record<string, any> = any,
|
||||||
> =
|
> =
|
||||||
| ConcreteComponent<Props, RawBindings, D, C, M, E, S>
|
| ConcreteComponent<PropsOrInstance, RawBindings, D, C, M, E, S>
|
||||||
| ComponentPublicInstanceConstructor<Props>
|
| ComponentPublicInstanceConstructor<PropsOrInstance>
|
||||||
|
|
||||||
export type { ComponentOptions }
|
export type { ComponentOptions }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue