【问题标题】:typescript vuejs interface imported and used but complains not usedtypescript vuejs 接口导入并使用但抱怨未使用
【发布时间】:2020-10-06 01:11:57
【问题描述】:
<template>
    <div>
        <div v-if="$root.isNotEmptyObj(error422)">
            <p v-for="error in error422.errors" v-bind:key="error.message">
                <span v-for="message in error.messages">{{ $t(message) }}</span>
            </p>
        </div>
    </div>
</template>

<script lang="ts">
  import { Component, Prop, Vue } from 'vue-property-decorator';
  import { Generic422 } from '@/api/ms-authentication/services/interfaces';

  @Component
  export default class MFormError422 extends Vue {
    @Prop()
    private error422!: Generic422;
  }
</script>

所以上面的组件导入 Generic422 作为私有类变量的类型。但是 ide 和 linter 抱怨说它没有被使用。

我在这里正确定义了道具吗?我真的只想要典型的 typescript 支持,以确保 prop 正确注入。

eslint 文件:

module.exports = {
  // Which files to not lint
  ignorePatterns: [
    'node_modules',
    'src/api/**/*',
    'tests/**/*',
  ],

  extends: [
    'plugin:vue/essential',
    'eslint:recommended',
    '@vue/typescript'
  ],
  rules: {
  }
}

【问题讨论】:

    标签: typescript vue.js


    【解决方案1】:
    module.exports = {
      // Which files to not lint
      ignorePatterns: [
        'node_modules',
        'src/api/**/*',
        'tests/**/*',
      ],
    
      extends: [
        'plugin:vue/essential',
        'eslint:recommended',
        '@vue/typescript'
      ],
    
      // additional function from 3rd parties
      plugins: [
        'deprecate',
      ],
    
      rules: {
        '@typescript-eslint/no-explicit-any': 'off',
        '@typescript-eslint/no-unused-vars': [
          'error',
          { vars: 'all', args: 'none', ignoreRestSiblings: false },
        ],
        quotes: ['error', 'single', { avoidEscape: true }],
        curly: ['error', 'all'],
        'max-lines-per-function': ['error', 40],
        'deprecate/function': 2,
        'deprecate/member-expression': 2,
        'deprecate/import': 2,
      }
    }
    

    这个 lint 文件修复了它

    【讨论】:

    • +1 非常感谢您为我指明了正确的方向。但是,我不赞成不研究细节并了解哪个特定规则解决了问题以及问题是什么。在我看来,不应该在不了解每个设置的情况下复制/粘贴 eslint 设置。
    【解决方案2】:

    这是你需要在.eslintrc.jsrules中设置的具体规则:

    '@typescript-eslint/no-unused-vars': [
      'error',
      { ignoreRestSiblings: false }
    ]
    

    记录在案的here

    【讨论】:

      猜你喜欢
      • 2020-08-14
      • 1970-01-01
      • 2023-03-18
      • 2020-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多