diff --git a/package.json b/package.json index 540ba574e..db304f1dc 100644 --- a/package.json +++ b/package.json @@ -119,6 +119,9 @@ "react", "react-dom" ] + }, + "patchedDependencies": { + "@vue/runtime-core@3.3.8": "patches/@vue__runtime-core@3.3.8.patch" } } } diff --git a/patches/@vue__runtime-core@3.3.8.patch b/patches/@vue__runtime-core@3.3.8.patch new file mode 100644 index 000000000..a9628558d --- /dev/null +++ b/patches/@vue__runtime-core@3.3.8.patch @@ -0,0 +1,417 @@ +diff --git a/dist/runtime-core.d.ts b/dist/runtime-core.d.ts +index 5d4c1fb2c6859f7982ea7bb55f65a5c613d91038..d8c6502f88b63d58dd9844f460c39d519754f396 100644 +--- a/dist/runtime-core.d.ts ++++ b/dist/runtime-core.d.ts +@@ -1,7 +1,7 @@ + import { computed as computed$1, ShallowUnwrapRef, UnwrapNestedRefs, DebuggerEvent, ComputedGetter, WritableComputedOptions, Ref, ReactiveEffect, ComputedRef, DebuggerOptions, reactive } from '@vue/reactivity'; + export { ComputedGetter, ComputedRef, ComputedSetter, CustomRefFactory, DebuggerEvent, DebuggerEventExtraInfo, DebuggerOptions, DeepReadonly, EffectScheduler, EffectScope, MaybeRef, MaybeRefOrGetter, Raw, ReactiveEffect, ReactiveEffectOptions, ReactiveEffectRunner, ReactiveFlags, Ref, ShallowReactive, ShallowRef, ShallowUnwrapRef, ToRef, ToRefs, TrackOpTypes, TriggerOpTypes, UnwrapNestedRefs, UnwrapRef, WritableComputedOptions, WritableComputedRef, customRef, effect, effectScope, getCurrentScope, isProxy, isReactive, isReadonly, isRef, isShallow, markRaw, onScopeDispose, proxyRefs, reactive, readonly, ref, shallowReactive, shallowReadonly, shallowRef, stop, toRaw, toRef, toRefs, toValue, triggerRef, unref } from '@vue/reactivity'; + import { IfAny, Prettify, Awaited, UnionToIntersection, LooseRequired } from '@vue/shared'; +-export { camelize, capitalize, normalizeClass, normalizeProps, normalizeStyle, toDisplayString, toHandlerKey } from '@vue/shared'; ++export { LooseRequired, camelize, capitalize, normalizeClass, normalizeProps, normalizeStyle, toDisplayString, toHandlerKey } from '@vue/shared'; + + export declare const computed: typeof computed$1; + +@@ -62,7 +62,7 @@ type EmitsToProps = T extends string[] ? { + } : T extends ObjectEmitsOptions ? { + [K in string & `on${Capitalize}`]?: K extends `on${infer C}` ? T[Uncapitalize] extends null ? (...args: any[]) => any : (...args: T[Uncapitalize] extends (...args: infer P) => any ? P : never) => any : never; + } : {}; +-type EmitFn = Options extends Array ? (event: V, ...args: any[]) => void : {} extends Options ? (event: string, ...args: any[]) => void : UnionToIntersection<{ ++type EmitFn = Options extends Array ? (event: V, ...args: any[]) => void : {} extends Options ? (event: any, ...args: any[]) => any | ((event: string, ...args: any[]) => void) : UnionToIntersection<{ + [key in Event]: Options[key] extends (...args: infer Args) => any ? (event: key, ...args: Args) => void : (event: key, ...args: any[]) => void; + }[Event]>; + +@@ -101,20 +101,39 @@ type ExtractMixin = { + type IntersectionMixin = IsDefaultMixinComponent extends true ? OptionTypesType : UnionToIntersection>; + type UnwrapMixinsType = T extends OptionTypesType ? T[Type] : never; + type EnsureNonVoid = T extends void ? {} : T; +-type ComponentPublicInstanceConstructor = ComponentPublicInstance, Props = any, RawBindings = any, D = any, C extends ComputedOptions = ComputedOptions, M extends MethodOptions = MethodOptions> = { ++/** ++ * ++ P = {}, // props type extracted from props option ++ B = {}, // raw bindings returned from setup() ++ D = {}, // return from data() ++ C extends ComputedOptions = {}, ++ M extends MethodOptions = {}, ++ E extends EmitsOptions = {}, ++ PublicProps = P, ++ Defaults = {}, ++ MakeDefaultsOptional extends boolean = false, ++ Options = ComponentOptionsBase, ++ I extends ComponentInjectOptions = {}, ++ S extends SlotsType = {} ++ */ ++type ComponentPublicInstanceConstructor = ComponentPublicInstance, Props = any, RawBindings = any, D = any, C extends ComputedOptions = ComputedOptions, M extends MethodOptions = MethodOptions, E extends EmitsOptions = {}, PublicProps = {}, Defaults = {}, MakeDefaultsOptional extends boolean = false, Options = ComponentOptionsBase, I extends ComponentInjectOptions = {}, S extends SlotsType = {}> = { + __isFragment?: never; + __isTeleport?: never; + __isSuspense?: never; + new (...args: any[]): T; + }; +-export type CreateComponentPublicInstance

& IntersectionMixin, PublicP = UnwrapMixinsType & EnsureNonVoid

, PublicB = UnwrapMixinsType & EnsureNonVoid, PublicD = UnwrapMixinsType & EnsureNonVoid, PublicC extends ComputedOptions = UnwrapMixinsType & EnsureNonVoid, PublicM extends MethodOptions = UnwrapMixinsType & EnsureNonVoid, PublicDefaults = UnwrapMixinsType & EnsureNonVoid> = ComponentPublicInstance, I, S>; ++export type CreateComponentPublicInstance

, PublicMixin = IntersectionMixin & IntersectionMixin, PublicP = UnwrapMixinsType & EnsureNonVoid

, PublicB = UnwrapMixinsType & EnsureNonVoid, PublicD = UnwrapMixinsType & EnsureNonVoid, PublicC extends ComputedOptions = UnwrapMixinsType & EnsureNonVoid, PublicM extends MethodOptions = UnwrapMixinsType & EnsureNonVoid, PublicDefaults = UnwrapMixinsType & EnsureNonVoid> = ComponentPublicInstance; ++/** ++ * Resolves props ++ */ ++type ComponentPropsWithDefault = MakeDefaultsOptional extends true ? Partial & Omit & PublicProps, keyof Defaults> : Prettify

& PublicProps; + export type ComponentPublicInstance

, I extends ComponentInjectOptions = {}, S extends SlotsType = {}> = { ++C extends ComputedOptions = {}, M extends MethodOptions = {}, E extends EmitsOptions = {}, PublicProps = P, Defaults = {}, MakeDefaultsOptional extends boolean = false, Options = any, I extends ComponentInjectOptions = {}, S extends SlotsType = {}> = { + $: ComponentInternalInstance; + $data: D; +- $props: MakeDefaultsOptional extends true ? Partial & Omit & PublicProps, keyof Defaults> : Prettify

& PublicProps; ++ $props: ComponentPropsWithDefault; + $attrs: Data; + $refs: Data; + $slots: UnwrapSlotsType; +@@ -126,7 +145,7 @@ C extends ComputedOptions = {}, M extends MethodOptions = {}, E extends EmitsOpt + $forceUpdate: () => void; + $nextTick: typeof nextTick; + $watch any)>(source: T, cb: T extends (...args: any) => infer R ? (...args: [R, R]) => any : (...args: any) => any, options?: WatchOptions): WatchStopHandle; +-} & P & ShallowUnwrapRef & UnwrapNestedRefs & ExtractComputedReturns & M & ComponentCustomProperties & InjectToObject; ++} & IfAny>> & ShallowUnwrapRef & UnwrapNestedRefs & ExtractComputedReturns & M & ComponentCustomProperties & InjectToObject; + + declare const enum LifecycleHooks { + BEFORE_CREATE = "bc", +@@ -383,6 +402,7 @@ export type ComponentPropsOptions

= ComponentObjectPropsOptions

| s + export type ComponentObjectPropsOptions

= { + [K in keyof P]: Prop | null; + }; ++ + export type Prop = PropOptions | PropType; + type DefaultFactory = (props: Data) => T | null | undefined; + interface PropOptions { +@@ -467,7 +487,7 @@ export type ExtractPublicPropTypes = { + } & { + [K in keyof Pick>]?: InferPropType; + }; +-export type ExtractDefaultPropTypes = O extends object ? { ++export type ExtractDefaultPropTypes = [O] extends [object] ? { + [K in keyof Pick>]: InferPropType; + } : {}; + +@@ -514,6 +534,15 @@ export type DirectiveArguments = Array<[Directive | undefined] | [Directive | un + */ + export declare function withDirectives(vnode: T, directives: DirectiveArguments): T; + ++interface ComponentOptionsCompat extends ComponentOptions { ++ model?: any; ++ el?: any; ++ _base?: any; ++ options?: any; ++ propsData?: any; ++ parent?: any; ++ __isBuildIn?: boolean; ++} + export declare const enum DeprecationTypes { + GLOBAL_MOUNT = "GLOBAL_MOUNT", + GLOBAL_MOUNT_CONTAINER = "GLOBAL_MOUNT_CONTAINER", +@@ -610,19 +639,19 @@ export interface RuntimeCompilerOptions { + comments?: boolean; + delimiters?: [string, string]; + } +-export type ComponentOptionsWithoutProps> = ComponentOptionsBase & { ++export type ComponentOptionsWithoutProps> = ComponentOptionsBase & { + props?: undefined; + } & ThisType>; +-export type ComponentOptionsWithArrayProps>>> = ComponentOptionsBase & { ++} & EmitsToProps>>> = Omit, 'props'> & { + props: PropNames[]; + } & ThisType>; +-export type ComponentOptionsWithObjectProps & EmitsToProps>>, Defaults = ExtractDefaultPropTypes> = ComponentOptionsBase & { +- props: PropsOptions & ThisType; ++export type ComponentOptionsWithObjectProps> : Prettify & EmitsToProps>>, Defaults = ExtractDefaultPropTypes> = ComponentOptionsBase & { ++ props: PropsOptions & ThisType; + } & ThisType>; +-export type ComponentOptions = ComponentOptionsBase & ThisType>>; +-export type ComponentOptionsMixin = ComponentOptionsBase; ++export type ComponentOptions, RawBindings = any, D = any, C extends ComputedOptions = any, M extends MethodOptions = any, Mixin extends ComponentOptionsMixin = any, Extends extends ComponentOptionsMixin = any, E extends EmitsOptions = {}, I extends ComponentInjectOptions = {}, S extends SlotsType = any> = ComponentOptionsBase & ThisType, {}, false, I, S>>; ++export type ComponentOptionsMixin = ComponentOptionsBase; + export type ComputedOptions = Record | WritableComputedOptions>; + export interface MethodOptions { + [key: string]: Function; +@@ -652,7 +681,7 @@ type InjectToObject = T extends string[] ? { + } : never; + interface LegacyOptions { + compatConfig?: CompatConfig; +- [key: string]: any; ++ props?: ComponentPropsOptions | Readonly; + data?: (this: CreateComponentPublicInstance, vm: CreateComponentPublicInstance) => D; + computed?: C; + methods?: M; +@@ -814,6 +843,7 @@ export interface TeleportProps { + disabled?: boolean; + } + declare const TeleportImpl: { ++ name: string; + __isTeleport: boolean; + process(n1: TeleportVNode | null, n2: TeleportVNode, container: RendererElement, anchor: RendererNode | null, parentComponent: ComponentInternalInstance | null, parentSuspense: SuspenseBoundary | null, isSVG: boolean, slotScopeIds: string[] | null, optimized: boolean, internals: RendererInternals): void; + remove(vnode: VNode, parentComponent: ComponentInternalInstance | null, parentSuspense: SuspenseBoundary | null, optimized: boolean, { um: unmount, o: { remove: hostRemove } }: RendererInternals, doRemove: boolean): void; +@@ -883,7 +913,7 @@ export type VNodeProps = { + onVnodeBeforeUnmount?: VNodeMountHook | VNodeMountHook[]; + onVnodeUnmounted?: VNodeMountHook | VNodeMountHook[]; + }; +-type VNodeChildAtom = VNode | typeof NULL_DYNAMIC_COMPONENT | string | number | boolean | null | undefined | void; ++type VNodeChildAtom = VNode | string | number | boolean | null | undefined | void; + export type VNodeArrayChildren = Array; + export type VNodeChild = VNodeChildAtom | VNodeArrayChildren; + export type VNodeNormalizedChildren = string | VNodeArrayChildren | RawSlots | null; +@@ -1037,7 +1067,7 @@ interface ClassComponent { + * values, e.g. checking if its a function or not. This is mostly for internal + * implementation code. + */ +-export type ConcreteComponent = ComponentOptions | FunctionalComponent; ++export type ConcreteComponent, RawBindings = any, D = any, C extends ComputedOptions = ComputedOptions, M extends MethodOptions = MethodOptions, E extends EmitsOptions = any, I extends ComponentInjectOptions = any, S extends SlotsType = any> = (ComponentOptions & Record) | FunctionalComponent; + /** + * A type used in public APIs where a component type is expected. + * The constructor type is an artificial type returned by defineComponent(). +@@ -1123,9 +1153,24 @@ export declare function watch, Immediate e + export declare function watch = false>(source: WatchSource, cb: WatchCallback, options?: WatchOptions): WatchStopHandle; + export declare function watch = false>(source: T, cb: WatchCallback, options?: WatchOptions): WatchStopHandle; + +-type PublicProps = VNodeProps & AllowedComponentProps & ComponentCustomProps; +-type ResolveProps = Readonly : PropsOrPropOptions> & ({} extends E ? {} : EmitsToProps); +-export type DefineComponent, Defaults = ExtractDefaultPropTypes, S extends SlotsType = {}> = ComponentPublicInstanceConstructor & Props> & ComponentOptionsBase & PP; ++type PublicProps$1 = VNodeProps & AllowedComponentProps & ComponentCustomProps; ++type ResolveProps = Readonly<([Props] extends [string] ? { ++ [key in Props]?: any; ++} : [Props] extends [ComponentObjectPropsOptions] ? ExtractPropTypes : Props extends never[] ? {} : Props) & ({} extends E ? {} : EmitsToProps)>; ++declare const RawOptionsSymbol: '__rawOptions'; ++export type DefineComponent, Defaults = ExtractDefaultPropTypes, I extends ComponentInjectOptions = {}, II extends string = string, S extends SlotsType = {}, Options = {}> = ComponentPublicInstanceConstructor> & Omit, 'props'> & { ++ props: PropsOrPropOptions; ++} & Omit & { ++ [RawOptionsSymbol]: Options; ++} & PP; ++export type DefineComponentOptions = (Options & { ++ props?: [Props] extends [never] ? string[] : [Props] extends [string] ? Array : Props; ++} & ([Props] extends [string] ? ComponentOptionsWithArrayProps : [Props] extends [undefined] ? { ++ props?: undefined; ++} & ComponentOptionsWithoutProps<{}, RawBindings, D, C, M, Mixin, Extends, E, EE, I, II, S> : Props extends ComponentObjectPropsOptions ? ComponentOptionsWithObjectProps : ComponentOptions & EmitsToProps>, RawBindings, D, C, M, Mixin, Extends, E, I, S>)) | (((props: Props, ctx: SetupContext) => RenderFunction | Promise) & Options); ++export type DefineComponentFromOptions = DefineComponent<[ ++ Props ++] extends [string] ? Props[] : undefined extends Props ? {} : Props extends never[] ? string[] : Props, RawBindings, D, C, M, Mixin, Extends, E, EE, PublicProps$1, ResolveProps, ExtractDefaultPropTypes, I, II, S, Options>; + export declare function defineComponent, E extends EmitsOptions = {}, EE extends string = string, S extends SlotsType = {}>(setup: (props: Props, ctx: SetupContext) => RenderFunction | Promise, options?: Pick & { + props?: (keyof Props)[]; + emits?: E | EE[]; +@@ -1136,11 +1181,9 @@ export declare function defineComponent, E ext + emits?: E | EE[]; + slots?: S; + }): (props: Props & EmitsToProps) => any; +-export declare function defineComponent(options: ComponentOptionsWithoutProps): DefineComponent, ExtractDefaultPropTypes, S>; +-export declare function defineComponent>(options: ComponentOptionsWithArrayProps): DefineComponent, ExtractDefaultPropTypes, S>; +-export declare function defineComponent, RawBindings, D, C extends ComputedOptions = {}, M extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, E extends EmitsOptions = {}, EE extends string = string, S extends SlotsType = {}, I extends ComponentInjectOptions = {}, II extends string = string>(options: ComponentOptionsWithObjectProps): DefineComponent, ExtractDefaultPropTypes, S>; ++export declare function defineComponent(options: Options & ComponentOptionsWithoutProps): DefineComponent, ExtractDefaultPropTypes, I, II, S, Options>; ++export declare function defineComponent(options: DefineComponentOptions): DefineComponentFromOptions; ++export declare function defineComponent(options: Options & ComponentOptionsWithObjectProps): DefineComponent, ExtractDefaultPropTypes, I, II, S, Options>; + + type AsyncComponentResolveResult = T | { + default: T; +@@ -1196,7 +1239,7 @@ export declare function defineProps(props: Pr + [key in PropNames]?: any; + }>>; + export declare function defineProps(props: PP): Prettify>>; +-export declare function defineProps(): DefineProps>; ++export declare function defineProps(): DefineProps, BooleanKey>; + type DefineProps = Readonly & { + readonly [K in BKeys]-?: boolean; + }; +@@ -1319,8 +1362,8 @@ type InferDefaults = { + }; + type NativeType = null | number | string | boolean | symbol | Function; + type InferDefault = ((props: P) => T & {}) | (T extends NativeType ? T : never); +-type PropsWithDefaults, BKeys extends keyof T> = Omit & { +- [K in keyof Defaults]-?: K extends keyof T ? Defaults[K] extends undefined ? T[K] : NotUndefined : never; ++type PropsWithDefaults, BKeys extends keyof T> = Readonly> & { ++ readonly [K in keyof Defaults]-?: K extends keyof T ? Defaults[K] extends undefined ? T[K] : NotUndefined : never; + } & { + readonly [K in BKeys]-?: K extends keyof Defaults ? Defaults[K] extends undefined ? boolean | undefined : boolean : boolean; + }; +@@ -1374,7 +1417,6 @@ export declare function h(type: typeof Teleport, props: RawProps & TeleportProps + export declare function h(type: typeof Suspense, children?: RawChildren): VNode; + export declare function h(type: typeof Suspense, props?: (RawProps & SuspenseProps) | null, children?: RawChildren | RawSlots): VNode; + export declare function h = {}>(type: FunctionalComponent, props?: (RawProps & P) | ({} extends P ? null : never), children?: RawChildren | RawSlots): VNode; +-export declare function h(type: Component, children?: RawChildren): VNode; + export declare function h

(type: ConcreteComponent | string, children?: RawChildren): VNode; + export declare function h

(type: ConcreteComponent

| string, props?: (RawProps & P) | ({} extends P ? null : never), children?: RawChildren): VNode; + export declare function h

(type: Component

, props?: (RawProps & P) | null, children?: RawChildren | RawSlots): VNode; +@@ -1383,8 +1425,10 @@ export declare function h(type: Constructor, children?: RawChildren): VNode; + export declare function h

(type: Constructor

, props?: (RawProps & P) | ({} extends P ? null : never), children?: RawChildren | RawSlots): VNode; + export declare function h(type: DefineComponent, children?: RawChildren): VNode; + export declare function h

(type: DefineComponent

, props?: (RawProps & P) | ({} extends P ? null : never), children?: RawChildren | RawSlots): VNode; +-export declare function h(type: string | Component, children?: RawChildren): VNode; +-export declare function h

(type: string | Component

, props?: (RawProps & P) | ({} extends P ? null : never), children?: RawChildren | RawSlots): VNode; ++export declare function h(type: VNode, children?: RawChildren): VNode; ++export declare function h

(type: VNode, props?: (RawProps & P) | ({} extends P ? null : never), children?: RawChildren | RawSlots): VNode; ++export declare function h(type: VNode | string | Constructor, children?: RawChildren): VNode; ++export declare function h

(type: VNode | string | Component

, props?: (RawProps & P) | ({} extends P ? null : never), children?: RawChildren | RawSlots): VNode; + + export declare const ssrContextKey: unique symbol; + export declare const useSSRContext: >() => T | undefined; +@@ -1437,6 +1481,138 @@ interface DevtoolsHook { + export declare let devtools: DevtoolsHook; + export declare function setDevtoolsHook(hook: DevtoolsHook, target: any): void; + ++/** ++ * Extracts the component original options ++ */ ++export type ExtractComponentOptions = T extends { ++ [RawOptionsSymbol]: infer Options; ++} ? Options : T extends ComponentOptionsBase ? T : T extends { ++ props?: any; ++ emits?: any; ++ slots?: any; ++} ? T : T; ++export type ExtractComponentProp = T extends { ++ props: infer P; ++} ? P : T extends (props: infer P) => any ? P : T extends { ++ new (): { ++ $props: infer P; ++ }; ++} ? P : {}; ++/** ++ * Extracts the component slots as the component was created ++ */ ++export type ExtractComponentSlots = T extends ComponentOptionsBase ? S : T extends { ++ slots: infer S; ++} ? S : T extends { ++ slots: infer S extends Slots; ++} ? S : T extends (props: any, opts: infer Ctx extends { ++ slots: any; ++}) => any ? Ctx['slots'] : T extends (props: any, opts: SetupContext) => any ? S : T extends { ++ new (): { ++ $slots: infer S extends Slots; ++ }; ++} ? S : {}; ++/** ++ * Extracts the component emits as the component was created ++ */ ++export type ExtractComponentEmits = T extends ComponentOptionsBase ? E : T extends { ++ emits: infer E; ++} ? E : T extends { ++ emits: infer E extends EmitsOptions; ++} ? E : T extends (props: any, opts: { ++ emits: infer E extends EmitsOptions; ++}) => any ? E : T extends { ++ $options: infer Options; ++} ? Options extends { ++ emits: infer E; ++} ? E : {} : {}; ++type ResolveMixin = [T] extends [ ++ Readonly> ++] ? IntersectionMixin & IntersectionMixin : {}; ++export type ObjectToComponentProps = T extends Record ? { ++ [K in keyof T]: { ++ type: PropType; ++ required: T[K] extends undefined ? false : true; ++ }; ++} : {}; ++/** ++ * Extracts Original props from options ++ */ ++export type ResolvePropsFromOptions = T extends { ++ props: infer P; ++} ? [P] extends [Array] ? [PA] extends [string] ? ObjectToComponentProps> : never : P : T extends (props: infer P, ctx?: any) => any ? ObjectToComponentProps

: T extends { ++ new (): { ++ $props: infer P; ++ }; ++} ? ObjectToComponentProps

: T; ++/** ++ * Get the Component props making the default optional ++ * Used mainly on the render component ++ */ ++export type ComponentPropsWithDefaultOptional = (ResolvePropsFromOptions extends infer Props ? ExtractDefaultPropTypes extends infer Defaults ? Partial & Omit, keyof Defaults> : {} : {}) & (T extends { ++ props: any; ++} ? ResolveMixinProps> : T extends ((...args: any) => any) | (abstract new (...args: any) => any) ? {} : ResolveMixinProps); ++type FixMixinResolve = [T] extends [never] ? {} : T; ++type ResolveMixinProps = UnwrapMixinsType, 'P'>; ++type ResolveMixinData = FixMixinResolve, 'D'>>; ++/** ++ * Returns the emits as props ++ */ ++export type ComponentEmitsProps = ExtractComponentEmits extends infer E ? E extends EmitsOptions ? EmitsToProps : unknown : unknown; ++/** ++ * Returns runtime props definition for a component ++ * ++ * @see Include emits {@linkcode ComponentEmitsProps} ++ * @see Get the render props {@linkcode ComponentPropsWithDefaultOptional} ++ * ++ * @example ++ * ```ts ++ * import { Comp } from './Comp.vue' ++ * ++ * function useProps(): ComponentProps { ++ * // ... ++ * } ++ * ``` ++ */ ++export type ComponentProps = T extends { ++ $props: infer P; ++} ? P : (ExtractComponentProp extends infer P ? P extends Readonly> ? [V] extends [string] ? Readonly<{ ++ [key in V]?: any; ++}> : {} : P extends ComponentPropsOptions ? ExtractPropTypes

: P : {}) & ResolveMixinProps; ++export type RetrieveSlotArgument = ((...args: T) => any) | undefined; ++/** ++ * Returns runtime type for `slots` ++ */ ++export type ComponentSlots = ExtractComponentSlots extends infer S ? S extends SlotsType ? Record extends SS ? { ++ [K in keyof S & string]: S[K] extends RetrieveSlotArgument ? (...arg: A) => VNode[] : (arg: S[K]) => VNode[]; ++} : UnwrapSlotsType : S extends Record ? { ++ [K in keyof S & string]: S[K] extends RetrieveSlotArgument ? (...arg: A) => VNode[] : (arg: S[K]) => VNode[]; ++} : {} : {}; ++export type ComponentEmits = ExtractComponentEmits extends infer E ? {} extends E ? () => void : EmitFn : () => void; ++export type ComponentData = (T extends { ++ data: () => infer D; ++} ? D : T extends { ++ setup(...args: any[]): infer S; ++} ? S extends Record ? S : {} : T extends new () => { ++ data: () => infer D; ++} ? D : {}) & ResolveMixinData; ++/** ++ * Retrieves the component public instance ++ * ++ * @example ++ * ```ts ++ * const Comp = defineComponent({ props: { a: String }, emits: ['test'] }) ++ * ++ * const instance = ref>() ++ * instance.$props.a // string | undefined ++ * ``` ++ */ ++export type ComponentInstance = T extends { ++ new (): ComponentPublicInstance; ++} ? InstanceType : T extends FunctionalComponent ? ComponentPublicInstance : T extends ComponentPublicInstanceConstructor ? InstanceType : T extends DefineComponentOptions ? InstanceType ? PA : P : Props, RawBindings, D, C, M, Mixin, Extends, E, EE, I, II, S, Options>>> : T extends Component ? ComponentPublicInstance : never; ++ + type HMRComponent = ComponentOptions | ClassComponent; + export interface HMRRuntime { + createRecord: typeof createRecord; +@@ -1568,12 +1744,12 @@ interface LegacyPublicProperties { + */ + export type CompatVue = Pick & { + configureCompat: typeof configureCompat; +- new (options?: ComponentOptions): LegacyPublicInstance; ++ new (options?: ComponentOptionsCompat): LegacyPublicInstance; + version: string; + config: AppConfig & LegacyConfig; + nextTick: typeof nextTick; + use(plugin: Plugin, ...options: any[]): CompatVue; +- mixin(mixin: ComponentOptions): CompatVue; ++ mixin(mixin: ComponentOptionsCompat): CompatVue; + component(name: string): Component | undefined; + component(name: string, component: Component): CompatVue; + directive(name: string): Directive | undefined; +@@ -1582,7 +1758,7 @@ export type CompatVue = Pick & { + /** + * @deprecated Vue 3 no longer supports extending constructors. + */ +- extend: (options?: ComponentOptions) => CompatVue; ++ extend: (options?: ComponentOptionsCompat) => CompatVue; + /** + * @deprecated Vue 3 no longer needs set() for adding new properties. + */ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a166b7dbc..06047af33 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,11 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false +patchedDependencies: + '@vue/runtime-core@3.3.8': + hash: vlyf6crnsg7mzuzbrcghr6xpce + path: patches/@vue__runtime-core@3.3.8.patch + dependencies: js-beautify: specifier: ^1.14.9 @@ -1643,17 +1648,18 @@ packages: '@vue/shared': 3.3.8 dev: true - /@vue/runtime-core@3.3.8: + /@vue/runtime-core@3.3.8(patch_hash=vlyf6crnsg7mzuzbrcghr6xpce): resolution: {integrity: sha512-qurzOlb6q26KWQ/8IShHkMDOuJkQnQcTIp1sdP4I9MbCf9FJeGVRXJFr2mF+6bXh/3Zjr9TDgURXrsCr9bfjUw==} dependencies: '@vue/reactivity': 3.3.8 '@vue/shared': 3.3.8 dev: true + patched: true /@vue/runtime-dom@3.3.8: resolution: {integrity: sha512-Noy5yM5UIf9UeFoowBVgghyGGPIDPy1Qlqt0yVsUdAVbqI8eeMSsTqBtauaEoT2UFXUk5S64aWVNJN4MJ2vRdA==} dependencies: - '@vue/runtime-core': 3.3.8 + '@vue/runtime-core': 3.3.8(patch_hash=vlyf6crnsg7mzuzbrcghr6xpce) '@vue/shared': 3.3.8 csstype: 3.1.2 dev: true diff --git a/src/baseWrapper.ts b/src/baseWrapper.ts index 71f074bf5..a1eb9ace0 100644 --- a/src/baseWrapper.ts +++ b/src/baseWrapper.ts @@ -1,13 +1,20 @@ import { textContent } from './utils' import type { TriggerOptions } from './createDomEvent' import { + DefineComponentOptions, + DefineComponentFromOptions, + ComponentInjectOptions, + ComponentInstance, ComponentInternalInstance, ComponentOptions, + ComponentOptionsMixin, ComponentPublicInstance, ComputedOptions, CreateComponentPublicInstance, + EmitsOptions, FunctionalComponent, MethodOptions, + SlotsType, nextTick } from 'vue' import { createDOMEvent } from './createDomEvent' @@ -19,6 +26,7 @@ import { FindComponentSelector, NameSelector, RefSelector, + UnknownRenderedVue, VueNode } from './types' import WrapperLike from './interfaces/wrapperLike' @@ -108,16 +116,57 @@ export default abstract class BaseWrapper // searching by string without specifying component results in WrapperLike object findComponent(selector: string): WrapperLike + // Find Component Options aka plain object findComponent< - Props, - RawBindings = any, - D = any, - C extends ComputedOptions = ComputedOptions, - M extends MethodOptions = MethodOptions + Props = {}, + RawBindings = {}, + D = {}, + C extends ComputedOptions = {}, + M extends MethodOptions = {}, + Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, + Extends extends ComponentOptionsMixin = ComponentOptionsMixin, + E extends EmitsOptions = {}, + EE extends string = string, + I extends ComponentInjectOptions = {}, + II extends string = string, + S extends SlotsType = {}, + Options = {} >( - selector: ComponentOptions - ): VueWrapper> + selector: DefineComponentOptions< + Props, + RawBindings, + D, + C, + M, + Mixin, + Extends, + E, + EE, + I, + II, + S, + Options + > + ): VueWrapper< + Props extends DefinedComponent + ? ComponentInstance + : DefineComponentFromOptions< + Props, + RawBindings, + D, + C, + M, + Mixin, + Extends, + E, + EE, + I, + II, + S, + Options + > + > findComponent( selector: string ): VueWrapper< @@ -129,21 +178,23 @@ export default abstract class BaseWrapper infer M > ? CreateComponentPublicInstance - : VueWrapper + : CreateComponentPublicInstance > - // searching for component created via defineComponent results in VueWrapper of proper type - findComponent( - selector: T | Exclude - ): VueWrapper> // searching for functional component results in DOMWrapper findComponent(selector: T): DOMWrapper findComponent( selector: string ): DOMWrapper + // searching by name or ref always results in VueWrapper findComponent( selector: NameSelector | RefSelector - ): VueWrapper + ): VueWrapper + // searching for component created via defineComponent results in VueWrapper of proper type + findComponent( + selector: T | Exclude + ): VueWrapper> + findComponent( selector: T | FindComponentSelector ): VueWrapper @@ -185,7 +236,7 @@ export default abstract class BaseWrapper findAllComponents(selector: string): WrapperLike[] findAllComponents( selector: T | Exclude - ): VueWrapper>[] + ): VueWrapper>[] findAllComponents( selector: T ): DOMWrapper[] @@ -290,17 +341,17 @@ export default abstract class BaseWrapper } getComponent(selector: string): Omit + // searching by name or ref always results in VueWrapper + getComponent( + selector: NameSelector | RefSelector + ): Omit, 'exists'> getComponent( selector: T | Exclude - ): Omit>, 'exists'> + ): Omit>, 'exists'> // searching for functional component results in DOMWrapper getComponent( selector: T | string ): Omit, 'exists'> - // searching by name or ref always results in VueWrapper - getComponent( - selector: NameSelector | RefSelector - ): Omit getComponent( selector: T | FindComponentSelector ): Omit, 'exists'> diff --git a/src/interfaces/wrapperLike.ts b/src/interfaces/wrapperLike.ts index 50728db60..8d32d1b1b 100644 --- a/src/interfaces/wrapperLike.ts +++ b/src/interfaces/wrapperLike.ts @@ -8,7 +8,11 @@ import { RefSelector } from '../types' import { VueWrapper } from '../vueWrapper' -import { ComponentPublicInstance, FunctionalComponent } from 'vue' +import { + ComponentInstance, + ComponentPublicInstance, + FunctionalComponent +} from 'vue' import type { DOMWrapper } from '../domWrapper' export default interface WrapperLike { @@ -35,7 +39,7 @@ export default interface WrapperLike { findComponent(selector: string): WrapperLike findComponent( selector: T | Exclude - ): VueWrapper> + ): VueWrapper> findComponent( selector: T | string ): DOMWrapper @@ -50,7 +54,7 @@ export default interface WrapperLike { findAllComponents(selector: string): WrapperLike[] findAllComponents( selector: T | Exclude - ): VueWrapper>[] + ): VueWrapper>[] findAllComponents( selector: string ): DOMWrapper[] @@ -79,7 +83,7 @@ export default interface WrapperLike { getComponent(selector: string): Omit getComponent( selector: T | Exclude - ): Omit>, 'exists'> + ): Omit>, 'exists'> // searching for functional component results in DOMWrapper getComponent( selector: T | string diff --git a/src/mount.ts b/src/mount.ts index 327ffd509..bd8f8a893 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -1,30 +1,28 @@ -import { ComponentPublicInstance, DefineComponent, VNode } from 'vue' -import type { - ComponentExposed, - ComponentProps, +import { + ComponentPublicInstance, + DefineComponent, + VNode, + ComponentInstance, ComponentSlots -} from 'vue-component-type-helpers' +} from 'vue' import { createInstance } from './createInstance' import { MountingOptions } from './types' import { trackInstance } from './utils/autoUnmount' import { VueWrapper } from './vueWrapper' import { createVueWrapper } from './wrapperFactory' - -type ShimSlotReturnType = T extends (...args: infer P) => any - ? (...args: P) => any - : never +import { ComponentPropsWithDefaultOptional } from 'vue' type WithArray = T | T[] type ComponentData = T extends { data?(...args: any): infer D } ? D : {} -export type ComponentMountingOptions< - T, - P extends ComponentProps = ComponentProps -> = Omit>, 'slots'> & { +export type ComponentMountingOptions = Omit< + MountingOptions>, + 'slots' +> & { slots?: { [K in keyof ComponentSlots]: WithArray< - | ShimSlotReturnType[K]> + | ComponentSlots[K] | string | VNode | (new () => any) @@ -34,27 +32,11 @@ export type ComponentMountingOptions< } & Record export function mount< - T, - C = T extends ((...args: any) => any) | (new (...args: any) => any) - ? T - : T extends { props?: infer Props } - ? DefineComponent< - Props extends Readonly<(infer PropNames)[]> | (infer PropNames)[] - ? { [key in PropNames extends string ? PropNames : string]?: any } - : Props - > - : DefineComponent, - P extends ComponentProps = ComponentProps + T extends DefineComponent >( originalComponent: T, - options?: ComponentMountingOptions -): VueWrapper< - ComponentProps & ComponentData & ComponentExposed, - ComponentPublicInstance< - ComponentProps, - ComponentData & ComponentExposed & Omit> - > -> + options?: ComponentMountingOptions> +): VueWrapper> // implementation export function mount( diff --git a/src/renderToString.ts b/src/renderToString.ts index bac8d1cd6..21860ae98 100644 --- a/src/renderToString.ts +++ b/src/renderToString.ts @@ -1,23 +1,44 @@ import { renderToString as baseRenderToString } from '@vue/server-renderer' -import { DefineComponent } from 'vue' +import { ComponentProps, DefineComponent } from 'vue' import { createInstance } from './createInstance' import { ComponentMountingOptions } from './mount' import { RenderMountingOptions } from './types' +// export function renderToString< +// T, +// C = T extends ((...args: any) => any) | (new (...args: any) => any) +// ? T +// : T extends { props?: infer Props } +// ? DefineComponent< +// Props extends Readonly<(infer PropNames)[]> | (infer PropNames)[] +// ? { [key in PropNames extends string ? PropNames : string]?: any } +// : Props +// > +// : DefineComponent +// >( +// originalComponent: T, +// options?: ComponentMountingOptions & +// Pick, 'attachTo'> +// ): Promise + +// defineComponent export function renderToString< - T, - C = T extends ((...args: any) => any) | (new (...args: any) => any) - ? T - : T extends { props?: infer Props } - ? DefineComponent< - Props extends Readonly<(infer PropNames)[]> | (infer PropNames)[] - ? { [key in PropNames extends string ? PropNames : string]?: any } - : Props - > - : DefineComponent + T extends DefineComponent< + PropsOrOptions, + any, + any, + any, + any, + any, + any, + any, + any, + any + >, + PropsOrOptions >( originalComponent: T, - options?: ComponentMountingOptions & + options?: ComponentMountingOptions> & Pick, 'attachTo'> ): Promise diff --git a/src/types.ts b/src/types.ts index 46677534b..a0e7f03d4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -166,4 +166,9 @@ export type VueNode = T & { export type VueElement = VueNode -export type DefinedComponent = new (...args: any[]) => any +export type DefinedComponent = Component + +export type UnknownRenderedVue = { + $props: Record + $data: Record +} diff --git a/src/vnodeTransformers/stubComponentsTransformer.ts b/src/vnodeTransformers/stubComponentsTransformer.ts index 7f1a110fd..f11f74663 100644 --- a/src/vnodeTransformers/stubComponentsTransformer.ts +++ b/src/vnodeTransformers/stubComponentsTransformer.ts @@ -17,7 +17,8 @@ import { ComponentPropsOptions, ComponentObjectPropsOptions, Component, - ComponentOptions + AsyncComponentOptions, + VNode } from 'vue' import { hyphenate } from '../utils/vueShared' import { matchName } from '../utils/matchName' @@ -32,9 +33,9 @@ import { registerStub } from '../stubs' export type CustomCreateStub = (params: { name: string - component: ConcreteComponent + component: Component registerStub: (config: { source: Component; stub: Component }) => void -}) => ConcreteComponent +}) => ConcreteComponent | VNode interface StubOptions { name: string @@ -123,11 +124,14 @@ export const createStub = ({ } }) - const { __asyncLoader: asyncLoader } = type as ComponentOptions + const { __asyncLoader: asyncLoader } = type as { + __asyncLoader?: AsyncComponentOptions['loader'] + } if (asyncLoader) { asyncLoader().then(() => { registerStub({ - source: (type as ComponentOptions).__asyncResolved, + source: (type as { __asyncResolved: ConcreteComponent | undefined }) + .__asyncResolved!, stub }) }) diff --git a/src/vueWrapper.ts b/src/vueWrapper.ts index 0209dbb4d..8e839f266 100644 --- a/src/vueWrapper.ts +++ b/src/vueWrapper.ts @@ -1,4 +1,10 @@ -import { nextTick, App, ComponentPublicInstance, VNode } from 'vue' +import { + nextTick, + App, + ComponentPublicInstance, + VNode, + ExtractComponentEmits +} from 'vue' import { config } from './config' import domEvents from './constants/dom-events' @@ -72,9 +78,29 @@ function createVMProxy( }) } +type ResolveComponentEmitKeys = keyof ResolveEmitRecord + +type ResolveEmitRecord = ExtractComponentEmits extends infer E + ? [E] extends [Array] + ? Record + : { + [K in keyof E]: (E[K] extends (...args: infer Args) => any + ? Args extends { length: 0 } + ? void + : Args extends { length: 1 } + ? Args[0] + : Args + : void)[] + } + : never + +type DeepPartial = { + [P in keyof T]?: DeepPartial +} + export class VueWrapper< VM = unknown, - T extends ComponentPublicInstance = VM & ComponentPublicInstance + T extends ComponentPublicInstance = ComponentPublicInstance & VM > extends BaseWrapper { private readonly componentVM: T private readonly rootVM: ComponentPublicInstance | undefined | null @@ -214,7 +240,6 @@ export class VueWrapper< get vm(): T { return this.componentVM } - props(): T['$props'] props( selector: Selector @@ -226,11 +251,16 @@ export class VueWrapper< return selector ? props[selector] : props } - emitted(): Record - emitted(eventName: string): undefined | T[] - emitted( - eventName?: string - ): undefined | T[] | Record { + emitted(): ResolveEmitRecord extends infer E + ? {} extends E + ? Record + : E + : never + emitted>( + eventName: E + ): undefined | ResolveEmitRecord[E] + emitted(eventName: string): undefined | any[] + emitted(eventName?: string) { return emitted(this.vm, eventName) } @@ -239,7 +269,7 @@ export class VueWrapper< return domWrapper.isVisible() } - setData(data: Record): Promise { + setData(data: DeepPartial): Promise { mergeDeep(this.componentVM.$data, data) return nextTick() } @@ -253,7 +283,14 @@ export class VueWrapper< return nextTick() } - setValue(value: unknown, prop?: string): Promise { + setValue< + V extends T['$props'] extends { modelValue?: infer MV } ? MV : never + >(value: V): Promise + setValue

( + value: T['$props'][P], + prop: P + ): Promise + setValue(value: unknown, prop?: unknown): Promise { const propEvent = prop || 'modelValue' this.vm.$emit(`update:${propEvent}`, value) return this.vm.$nextTick() diff --git a/src/wrapperFactory.ts b/src/wrapperFactory.ts index 429773e30..6eea52caa 100644 --- a/src/wrapperFactory.ts +++ b/src/wrapperFactory.ts @@ -1,4 +1,4 @@ -import { ComponentPublicInstance, App } from 'vue' +import { App, ComponentPublicInstance } from 'vue' import type { DOMWrapper as DOMWrapperType } from './domWrapper' import type { VueWrapper as VueWrapperType } from './vueWrapper' diff --git a/test-dts/findComponent.d-test.ts b/test-dts/findComponent.d-test.ts index deb64e1d1..e667876a4 100644 --- a/test-dts/findComponent.d-test.ts +++ b/test-dts/findComponent.d-test.ts @@ -1,5 +1,5 @@ import { expectType } from './index' -import { defineComponent } from 'vue' +import { ComponentInstance, defineComponent } from 'vue' import { DOMWrapper, mount, VueWrapper } from '../src' import WrapperLike from '../src/interfaces/wrapperLike' @@ -31,11 +31,13 @@ const wrapper = mount(AppWithDefine) // find by type - component definition const componentByType = wrapper.findComponent(ComponentToFind) -expectType>>(componentByType) +expectType>>( + componentByType +) // find by type - component definition with emits const componentWithEmitsByType = wrapper.findComponent(ComponentWithEmits) -expectType>>( +expectType>>( componentWithEmitsByType ) @@ -50,7 +52,7 @@ expectType(componentByString) // findi by string with specifying component const componentByStringWithParam = wrapper.findComponent('.foo') -expectType>>( +expectType>>( componentByStringWithParam ) @@ -66,7 +68,7 @@ expectType(componentByRef) const componentByRefWithType = wrapper.findComponent({ ref: 'foo' }) -expectType>>( +expectType>>( componentByRefWithType ) @@ -78,6 +80,12 @@ expectType(componentByName) const componentByNameWithType = wrapper.findComponent({ name: 'foo' }) -expectType>>( + + +declare const aaa : ComponentInstance +aaa.$props +componentByNameWithType.vm.$props + +expectType>>( componentByNameWithType ) diff --git a/test-dts/mount.d-test.ts b/test-dts/mount.d-test.ts index 5072a97cf..cfa1c5170 100644 --- a/test-dts/mount.d-test.ts +++ b/test-dts/mount.d-test.ts @@ -91,9 +91,9 @@ expectError( ) const AppWithArrayProps = { - props: ['a'], + props: ['a'] as ['a'], template: '' -} as const +} // accept props - vm is properly typed expectType( @@ -168,7 +168,6 @@ mount(ShimComponent, { } }) -// TODO it should work mount(ShimComponent, { data() { return { diff --git a/test-dts/shallowMount.d-test.ts b/test-dts/shallowMount.d-test.ts index af9c5fa5c..eb769cced 100644 --- a/test-dts/shallowMount.d-test.ts +++ b/test-dts/shallowMount.d-test.ts @@ -65,9 +65,9 @@ expectError( ) const AppWithArrayProps = { - props: ['a'], + props: ['a'] as ['a'], template: '' -} as const +} // accept props // vm is properly typed diff --git a/test-dts/tsconfig.tsd.json b/test-dts/tsconfig.tsd.json index f10ca8eb3..10a780a5c 100644 --- a/test-dts/tsconfig.tsd.json +++ b/test-dts/tsconfig.tsd.json @@ -3,14 +3,9 @@ "compilerOptions": { "noEmit": false, "skipLibCheck": true, - "experimentalDecorators": true, - "strictNullChecks": false + "experimentalDecorators": true + // "strictNullChecks": false }, - "exclude": [ - "../src", - ], - "include": [ - "../dist", - "../test-dts" - ] + "exclude": ["../src"], + "include": ["../dist", "../test-dts"] } diff --git a/test-dts/wrapper.d-test.ts b/test-dts/wrapper.d-test.ts index 1582f3d95..4d441d615 100644 --- a/test-dts/wrapper.d-test.ts +++ b/test-dts/wrapper.d-test.ts @@ -1,8 +1,11 @@ import { expectType } from './index' -import { defineComponent } from 'vue' +import { SlotsType, defineComponent } from 'vue' import { mount } from '../src' const AppWithDefine = defineComponent({ + emits: { + increment: (arg: { count: number }) => true + }, template: '' }) @@ -65,10 +68,10 @@ expectType(byClassArray[0].element) // event name without specific type let incrementEventWithoutType = wrapper.emitted('increment') -expectType(incrementEventWithoutType) +expectType<{ count: number }[] | undefined>(incrementEventWithoutType) // event name -let incrementEvent = wrapper.emitted<{ count: number }>('increment') +let incrementEvent = wrapper.emitted('increment') expectType<{ count: number }[] | undefined>(incrementEvent) expectType<{ count: number }>(incrementEvent![0]) @@ -143,20 +146,18 @@ expectType(propsWrapper.props('bar')) // @ts-expect-error :: unknown prop propsWrapper.props('badProp') -const requiredPropsWrapper = mount( - defineComponent({ - props: { - foo: { type: String, required: true }, - bar: { type: Number, required: true } - } - }), - { - props: { - foo: 'abc', - bar: 123 - } +const c = defineComponent({ + props: { + foo: { type: String, required: true }, + bar: { type: Number, required: true } } -) +}) +const requiredPropsWrapper = mount(c, { + props: { + foo: 'abc', + bar: 123 + } +}) requiredPropsWrapper.setProps({ foo: 'abc' @@ -166,3 +167,52 @@ requiredPropsWrapper.setProps({ // @ts-expect-error wrong type foo: 1 }) + +// slots +mount( + defineComponent({ + slots: {} as SlotsType<{ + default: (test: { foo: string }) => void + }> + }), + { + slots: { + default: 'test' + } + } +) + +// slot type + +mount( + defineComponent({ + slots: {} as SlotsType<{ + default: (test: { foo: string }) => void + }> + }), + { + slots: { + // @ts-expect-error wrong type + nonExistent: 'test', + + default: (test) => { + expectType<{ foo: string }>(test) + // @ts-expect-error not any + expectType<{ bar: any }>(test) + } + } + } +) + +// required slots +mount( + defineComponent({ + slots: {} as SlotsType<{ + default: (test: { foo: string }) => void + }> + }), + { + // @ts-expect-error missing required slot + slots: {} + } +) diff --git a/tests/emit.spec.ts b/tests/emit.spec.ts index ffc4c6b4a..06eaab250 100644 --- a/tests/emit.spec.ts +++ b/tests/emit.spec.ts @@ -158,6 +158,7 @@ describe('emitted', () => { // Parent should emit custom event 'hello' but not 'hi' expect(wrapper.emitted().hello[0]).toEqual(['foo', 'bar']) + // @ts-expect-error `hi` is not a valid event expect(wrapper.emitted().hi).toEqual(undefined) // Child should emit custom event 'hi' expect(childWrapper.emitted().hi[0]).toEqual(['foo', 'bar']) @@ -165,6 +166,7 @@ describe('emitted', () => { // Additional events should accumulate in the same format wrapper.find('button').trigger('click') expect(wrapper.emitted().hello[1]).toEqual(['foo', 'bar']) + // @ts-expect-error `hi` is not a valid event expect(wrapper.emitted().hi).toEqual(undefined) expect(childWrapper.emitted().hi[1]).toEqual(['foo', 'bar']) }) @@ -340,6 +342,7 @@ describe('emitted', () => { const wrapper = mount(EmitsEventSFC) await wrapper.trigger('click') + // @ts-expect-error `click` is not defined expect(wrapper.emitted().click).toHaveLength(1) expect(wrapper.emitted().bar).toHaveLength(2) expect(wrapper.emitted().bar[0]).toEqual(['mounted']) @@ -350,6 +353,7 @@ describe('emitted', () => { const wrapper = mount(EmitsEventScriptSetup) await wrapper.trigger('click') + // @ts-expect-error `click` is not a valid event expect(wrapper.emitted().click).toHaveLength(1) expect(wrapper.emitted().bar).toHaveLength(2) expect(wrapper.emitted().bar[0]).toEqual(['mounted']) diff --git a/tests/features/teleport.spec.ts b/tests/features/teleport.spec.ts index 651495b32..6c71783bf 100644 --- a/tests/features/teleport.spec.ts +++ b/tests/features/teleport.spec.ts @@ -142,6 +142,8 @@ describe('teleport', () => { const withProps = wrapper.getComponent(EmitsEvent) withProps.trigger('click') + withProps.vm.$emit('greet') + expect(withProps.emitted().greet[0]).toEqual(['Hey!']) }) diff --git a/tests/setData.spec.ts b/tests/setData.spec.ts index 6e0edb35b..93955bf07 100644 --- a/tests/setData.spec.ts +++ b/tests/setData.spec.ts @@ -189,20 +189,18 @@ describe('setData', () => { }) it('should keep Date object on setData', async () => { - const wrapper = mount( - defineComponent({ - template: '

', - props: { modelValue: Date }, - data() { - return { value: this.modelValue } - } - }), - { - props: { - modelValue: new Date('2022-08-10T12:15:54Z') - } + const comp = defineComponent({ + template: '
', + props: { modelValue: Date }, + data() { + return { value: this.modelValue } } - ) + }) + const wrapper = mount(comp, { + props: { + modelValue: new Date('2022-08-10T12:15:54Z') + } + }) expect(wrapper.vm.value).toBeInstanceOf(Date) expect(wrapper.vm.value!.toISOString()).toBe('2022-08-10T12:15:54.000Z') diff --git a/tests/setProps.spec.ts b/tests/setProps.spec.ts index d58a7c7d7..bc287950a 100644 --- a/tests/setProps.spec.ts +++ b/tests/setProps.spec.ts @@ -23,7 +23,7 @@ describe('setProps', () => { it('updates a function prop', async () => { const Foo = { - props: ['obj'], + props: ['obj'] as ['obj'], template: `
foo
@@ -37,15 +37,15 @@ describe('setProps', () => { } } }) - expect(wrapper.html()).toContain('foo') + expect(wrapper.html()).toContain('foo') await wrapper.setProps({ obj: { foo: () => false } }) expect(wrapper.html()).not.toContain('foo') }) it('sets component props, and updates DOM when props were not initially passed', async () => { const Foo = { - props: ['foo'], + props: ['foo'] as ['foo'], template: `
{{ foo }}
` } @@ -126,11 +126,11 @@ describe('setProps', () => { it('allows using only on mounted component', async () => { const Foo = { name: 'Foo', - props: ['foo'], + props: ['foo'] as ['foo'], template: '
{{ foo }}
' } const Baz = { - props: ['baz'], + props: ['baz'] as ['baz'], template: '
', components: { Foo } } @@ -141,6 +141,7 @@ describe('setProps', () => { } }) const FooResult = wrapper.findComponent({ name: 'Foo' }) + expect(() => FooResult.setProps({ baz: 'bin' })).toThrowError( 'You can only use setProps on your mounted component' ) diff --git a/tests/trigger.spec.ts b/tests/trigger.spec.ts index 8293a3ca8..6b4173e1a 100644 --- a/tests/trigger.spec.ts +++ b/tests/trigger.spec.ts @@ -349,6 +349,7 @@ describe('trigger', () => { it('dispatches event', async () => { const Comp = defineComponent({ + emits: ['enter'], template: `