Subscribe on changes!

One of the overload of the `defineComponent` methods with a wrong default type

avatar
Jul 27th 2021

We got an error when using vue-tsc --noEmit to compile our Vue project.

  The last overload gave the following error.
    .......... hidden errors - It's not important ...........
              Types of parameters 'ctx' and 'ctx' are incompatible.
                Type 'SetupContext<string[]>' is not assignable to type 'SetupContext<EmitsOptions>'.
                  Type 'EmitsOptions' is not assignable to type 'string[]'.
                    Type 'ObjectEmitsOptions' is missing the following properties from type 'string[]': length, pop, push, concat, and 28 more.

18         const wrapper = mount(CurrentTime);

So I compared the @vue/test-utils/dist/mount.d.ts and @vue/runtime-core/dist/runtime-core.d.ts files, I see one of the overloads of the defineComponent methods with a different default type value.

export declare type DefineComponent<..., E extends EmitsOptions = Record<string, any>, ...> = ...;

export declare function defineComponent<Props, RawBindings = object>(setup: (props: Readonly<Props>, ctx: SetupContext) => RawBindings | RenderFunction): DefineComponent<Props, RawBindings>;

// The default type is defined as EmitsOptions, but other overloads and the definitions in @vue/test-utils is with Record<string, any>
export declare function defineComponent<..., E extends EmitsOptions = EmitsOptions, ...>(options: ...): DefineComponent<Props, RawBindings, D, C, M, Mixin, Extends, E, EE>;

export declare function defineComponent<..., E extends EmitsOptions = Record<string, any>, ...>(options: ...): DefineComponent<Readonly<{
    [key in PropNames]?: any;
}>, RawBindings, D, C, M, Mixin, Extends, E, EE>;

export declare function defineComponent<..., E extends EmitsOptions = Record<string, any>, ...>(options: ...): DefineComponent<PropsOptions, RawBindings, D, C, M, Mixin, Extends, E, EE>;

I think it would be a hidden issue. Since we are using shims definition for Vue so that it is difficult to find. For us, we temporarily use any as a workaround.

mount(CurrentTime as any)
avatar
Jul 27th 2021

Hello, thank you for taking time filling this issue!

However, we kindly ask you to use our Issue Helper when creating new issues, in order to ensure every issue provides the necessary information for us to investigate. This explains why your issue has been automatically closed by me (your robot friend!).

I hope to see your helper-created issue very soon!