Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vue3] compilation error in tests with TS project #5712

Closed
cexbrayat opened this issue Jul 24, 2020 · 2 comments · Fixed by #5722
Closed

[vue3] compilation error in tests with TS project #5712

cexbrayat opened this issue Jul 24, 2020 · 2 comments · Fixed by #5722

Comments

@cexbrayat
Copy link
Member

Version

4.5.0

Reproduction link

https://github.com/cexbrayat/vue-cli-playground

Environment info

macOS

Steps to reproduce

vue create vue-cli-playground -m yarn --inlinePreset '{"useConfigFiles": true,"plugins": {"@vue/cli-plugin-typescript": {"classComponent": false},"@vue/cli-plugin-unit-jest": {}},"vueVersion": "3"}'
cd vue-cli-playground
yarn serve

What is expected?

The applications starts with no error

What is actually happening?

The application starts but the compiler throws:

ERROR in /Users/ced-pro/Code/test/cli-tests/vue-cli-playground/tests/unit/example.spec.ts(7,34):
7:34 No overload matches this call.
  The last overload gave the following error.
    Argument of type '{}' is not assignable to parameter of type 'ComponentOptionsWithObjectProps<readonly string[] | Readonly<ComponentObjectPropsOptions<Record<string, unknown>>>, unknown, unknown, {}, {}, Record<string, any>, ComponentOptionsMixin, ComponentOptionsMixin, string, Readonly<...> | Readonly<...>>'.
      Property 'props' is missing in type '{}' but required in type '{ props: readonly string[] | Readonly<ComponentObjectPropsOptions<Record<string, unknown>>>; }'.
     5 |   it('renders props.msg when passed', () => {
     6 |     const msg = 'new message'
  >  7 |     const wrapper = shallowMount(HelloWorld, {
       |                                  ^
     8 |       props: { msg }
     9 |     })
    10 |     expect(wrapper.text()).toMatch(msg)

The real issue is that even if we update the shim, the error does not go away.
For example, typing component as any should do the trick:

declare module '*.vue' {
  const component: any
  export default component
}

But the error is the same. It looks like the shim is not properly picked up (even if removing the cache before launching yarn serve).

My current workaround is to disable the fork-ts-checker plugin that seems to be the culprit.

module.exports = {
  chainWebpack: config => {
    // fork-ts-checker is sadly ignoring the Vue shim
    // and throws incorrect errors
    // we disable it as it is just a nice to have to speed up the build
    config.plugins.delete('fork-ts-checker');
    config.module
      .rule('ts')
      .use('ts-loader')
      .tap(options => {
        return { ...options, transpileOnly: false };
      });
  }
};

With this plugin disabled, the application compiles fine. (note that I had the same issue when using vue-next-plugin previously).

@haoqunjiang
Copy link
Member

Seems updating the fork-ts-checker-webpack-plugin helps.
But that's breaking change for the CLI plugin…

@cexbrayat
Copy link
Member Author

👍
Maybe we could make the Vue 3 preset use the newer version of the plugin?

Or if we can't, even if it is breaking, might be a good thing to update it anyway?

haoqunjiang added a commit to haoqunjiang/vue-cli that referenced this issue Jul 28, 2020
Fixes vuejs#5712

Note this is a optional dependency so that we don't break compatibility
with Node.js v8.
haoqunjiang added a commit that referenced this issue Jul 29, 2020
…5722)

Fixes #5712

Note this is a optional dependency so that we don't break compatibility
with Node.js v8.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants