johnsoncodehk / vue-tsc

vue-tsc --noEmit && vite build
https://www.npmjs.com/package/vue-tsc
MIT License
241 stars 6 forks source link

How to ignore some errors and complete the build? #43

Closed calebeaires closed 3 years ago

calebeaires commented 3 years ago

Vue Version 2.^2.6.11 vue-tsc = ^0.2.0

When trying to migrate from vue-cli to Vite and using vue-tsc I am getting many issues on the build that I hadn't before. Problemas like

  1. Cannot find name 'field'
  2. The '>' operator cannot be applied to type 'symbol'
  3. Property 'assets' does not exist on type '{}'

Some of those problems come from a bad code, but others can pass without any problems. For example, here is some code.

vue-tsc does not recognize a prop when it is declared at the decorator @Component


<template>
{{field}}
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';

@Component({
    props: {
        field: Object,
    }
})
export default class FieldOptions extends Vue {}
// error = error TS2304: Cannot find name 'field'.
{
  "compilerOptions": {
    "strict": true,
    "target": "esnext",
    "module": "esnext",
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "noImplicitAny": false,
    "noEmit": true,
    "strictNullChecks": false,
    "allowSyntheticDefaultImports": true,
    "noImplicitAnyForClassMembers": false,
    "sourceMap": true,
    "resolveJsonModule": true,
    "noVarRequires": false,
    "baseUrl": ".",
    "types": [
      "vite/client"
    ],
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

I have found some workaround like use of Vue.extend to declare props. But my project is very big and I would like to find some other solution without change everthing.

johnsoncodehk commented 3 years ago

See https://github.com/johnsoncodehk/volar/issues/245.

You could use @ts-ignore to ignore some error in specific lines. But in your case, I recommend you just remove vue-tsc to ignore all type-checking on build, because when you give up complete type safety, there is no point in using vue-tsc. And you can still found all vue-tsc's errors in IDE with volar.

calebeaires commented 3 years ago

Thanks for the tip! I will keep it at another script directive. Fix type issues in the future.