vuejs / vue-cli

🛠️ webpack-based tooling for Vue.js Development
https://cli.vuejs.org/
MIT License
29.76k stars 6.33k forks source link

tsc does not detect errors in .vue files #5192

Open RobertOrthofer opened 4 years ago

RobertOrthofer commented 4 years ago

Version

4.1.1

Reproduction link

https://github.com/RobertOrthofer/typescript-vue

Environment info

  System:
    OS: macOS 10.15.2
    CPU: (4) x64 Intel(R) Core(TM) i5-5350U CPU @ 1.80GHz
  Binaries:
    Node: 12.13.1 - ~/.nvm/versions/node/v12.13.1/bin/node
    Yarn: Not Found
    npm: 6.12.1 - ~/.nvm/versions/node/v12.13.1/bin/npm
  Browsers:
    Chrome: 80.0.3987.106
    Firefox: 70.0.1
    Safari: 13.0.4
  npmPackages:
    @vue/cli-overlay:  4.2.2 
    @vue/cli-plugin-eslint: ^4.2.0 => 4.2.2 
    @vue/cli-plugin-router:  4.2.2 
    @vue/cli-plugin-typescript: ^4.2.0 => 4.2.2 
    @vue/cli-plugin-vuex:  4.2.2 
    @vue/cli-service: ^4.2.0 => 4.2.2 
    @vue/cli-shared-utils:  4.2.2 
    @vue/component-compiler-utils:  3.1.1 
    @vue/eslint-config-standard: ^5.1.0 => 5.1.2 
    @vue/eslint-config-typescript: ^5.0.1 => 5.0.1 
    @vue/preload-webpack-plugin:  1.1.1 
    @vue/web-component-wrapper:  1.2.0 
    eslint-plugin-vue: ^6.1.2 => 6.2.1 
    typescript: ~3.7.5 => 3.7.5 
    vue: ^2.6.11 => 2.6.11 
    vue-eslint-parser:  7.0.0 
    vue-hot-reload-api:  2.3.4 
    vue-loader:  15.9.0 
    vue-style-loader:  4.1.2 
    vue-template-compiler: ^2.6.11 => 2.6.11 
    vue-template-es2015-compiler:  1.9.1 
  npmGlobalPackages:
    @vue/cli: 4.1.1

Steps to reproduce

npm install
npm run typecheck

What is expected?

The computed property foo in HelloWorld.vue has an incorrect return type. npm run typecheck should report that error like vetur does in VS Code

What is actually happening?

When running npm run typecheck no errors are shown.


Is there a way to configure the repository so typescript does not ignore .vue files? Our goal is to run typechecking in a CI.

haoqunjiang commented 4 years ago

Please use vti for type checking in .vue files. See https://github.com/vuejs/vetur/issues/1635

Maybe we need to document this somewhere.

FuDesign2008 commented 3 years ago

Meet the same problem, +1

haoqunjiang commented 3 years ago

Try vue-tsc

FuDesign2008 commented 3 years ago

Try vue-tsc

Thanks a lot.

sethidden commented 3 years ago

If you're coming to this issue because you've made a blatant error (eg. const a : number = "im a satring") in a .vue file and running npm run build (vue-cli-service build) doesnt report any errors here's what you need to do:

NOTE: I'm using vue 2

# check your installed ts plugin version
npm list --depth 0 @vue/cli-plugin-typescript

#bad output
└── @vue/cli-plugin-typescript@4.3.1  # <----- THIS IS BAD, TOO OLD VERSION

# how to fix
npm i -D @vue/cli-plugin-typescript@4.5.13
# now "npm list" should show
└── @vue/cli-plugin-typescript@4.5.13

#the version can sometimes be old even after the force npm install - if that's the case make sure to update the version in package.json also

After doing the above I have regular ts errors in .vue files when I do something stupid

FuDesign2008 commented 3 years ago
  1. vue-tsc only supports vue 3.x, does not support vue 2.x
  2. vti is not stable

🚧 WIP. This feature is not stable yet. 🚧

from https://vuejs.github.io/vetur/guide/vti.html

So, for just now, there is no good enough solution.

colinblaise commented 2 years ago
  1. vue-tsc only supports vue 3.x, does not support vue 2.x
  2. vti is not stable

🚧 WIP. This feature is not stable yet. 🚧 from https://vuejs.github.io/vetur/guide/vti.html

So, for just now, there is no good enough solution.

Shouldn't vue-tsc now be compatible with vue 2.7.6?

thisismydesign commented 2 years ago

vue-tsc worked for me with vue@2.6.14

colinblaise commented 2 years ago

I can run vue-tsc --noEmit, but vue-tsc --watch does not work. I was hoping vue-cli would swap it's watch mechanism to use vue-tsc