ESLint rule for not showing errors for typescript type definitions

I have a workflow that checks for ESLint errors by running yarn lint command.
Here is how the workflow looks like:

name: Build and deploy
on:
  push:
    branches:
      - '**'
env:
  app_name: support_case_ui
  bucket_name_dev: support-ui-static-files-dev
  bucket_name_prod: support-ui-static-files-prod
  IS_FEATURE: ${{ github.ref != 'refs/heads/release' && github.ref != 'refs/heads/main'}}
  IS_DEV: ${{ github.ref == 'refs/heads/main' }}
  NPM_TOKEN: ${{ secrets.READER_TOKEN }}
jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20.x
      - uses: actions/cache@v4
        id: yarn-cache
        with:
          path: .yarn/cache
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: Set environment variables for frontend build
        # Use environment variables from feature just for the build to go green. Using actual env variables in deploy step
        run: cat env/.env.dev >> $GITHUB_ENV 
      - name: Install yarn dependencies
        run: yarn --immutable
      - name: Check lint
        run: yarn lint
      - name: Run tests and build
        run: yarn test && yarn build

  deploy-to-feature:
    name: Deploy to feature
    runs-on: ubuntu-latest
    needs: build
    if: github.ref != 'refs/heads/main'
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20.x
      - uses: actions/cache@v4
        id: yarn-cache
        with:
          path: .yarn/cache
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: Install yarn dependencies
        run: yarn --immutable
      - name: Set environment variables for build
        run: cat env/.env.dev >> $GITHUB_ENV
      - name: Build app
        run: yarn build
      - name: Login GCP dev
        uses: google-github-actions/auth@v1
        with:
          credentials_json: ${{ secrets.GCP_SERVICEUSER_KEY_DEV }}
      - name: Set up Cloud SDK
        uses: google-github-actions/setup-gcloud@v1
      - name: Upload static files to feature GCP bucket
        run: gsutil -m rsync -R -d dist gs://${{env.bucket_name_dev}}/${{env.app_name}}/feature/static

  deploy-to-main:
    name: Deploy to main
    runs-on: ubuntu-latest
    needs: build
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20.x
      - uses: actions/cache@v4
        id: yarn-cache
        with:
          path: .yarn/cache
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: Install yarn dependencies
        run: yarn --immutable
      - name: Set environment variables for build
        run: cat env/.env.main >> $GITHUB_ENV
      - name: Build app
        run: yarn build
      - name: Login GCP dev
        uses: google-github-actions/auth@v1
        with:
          credentials_json: ${{ secrets.GCP_SERVICEUSER_KEY_DEV }}
      - name: Set up Cloud SDK
        uses: google-github-actions/setup-gcloud@v1
      - name: Upload static files to dev GCP bucket
        run: gsutil -m rsync -R -d dist gs://${{env.bucket_name_dev}}/${{env.app_name}}/main/static
  deploy-to-prod:
    name: Deploy to prod
    runs-on: ubuntu-latest
    needs: build
    if: github.ref == 'refs/heads/main'

    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20.x
      - uses: actions/cache@v4
        id: yarn-cache
        with:
          path: .yarn/cache
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: Install yarn dependencies
        run: yarn --immutable
      - name: Set environment variables for build
        run: cat env/.env.prod >> $GITHUB_ENV
      - name: Build app
        run: yarn build
      - name: Login GCP dev
        uses: google-github-actions/auth@v1
        with:
          credentials_json: ${{ secrets.GCP_SERVICEUSER_KEY_PROD }}
      - name: Set up Cloud SDK
        uses: google-github-actions/setup-gcloud@v1
      - name: Upload static files to prod GCP bucket
        run: gsutil -m rsync -R -d dist gs://${{env.bucket_name_prod}}/${{env.app_name}}/static

For this line of code:

type STEPSTYPE = { [key in Stepper]: number } | { [key in CaseStepper]: number };

I get an error when I run a workflow job:

Error:   52:86  error  'key' is defined but never used  @typescript-eslint/no-unused-vars

But if I run yarn lint locally on my computer I don’t get any errors. It runs without any errors:

yarn run v1.22.19
$ eslint ./src/**/*.{js,ts,tsx} package.json --quiet
✨  Done in 3.76s.

Is there any lint rule where I can avoid error for typescript type definitions, other than no-unused-vars? I would still like to get errors for unused vars, but in my case it is not a var, just a type that the error is being thrown for.

This is my current ESLint configuration:

module.exports = {
    parser: "@typescript-eslint/parser", // Specifies the ESLint parser
    parserOptions: {
        ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
        sourceType: "module", // Allows for the use of imports
        ecmaFeatures: {
            jsx: true, // Allows for the parsing of JSX
        },
    },
    settings: {
        react: {
            version: "detect", // Tells eslint-plugin-react to automatically detect the version of React to use
        },
        "json/sort-package-json": ["name", "version", "private", "scripts", "dependencies", "devDependencies"],
    },
    plugins: ["@typescript-eslint", "prettier", "json-format", "simple-import-sort", "unused-imports"],
    extends: [
        "eslint:recommended",
        "plugin:@typescript-eslint/eslint-recommended",
        "plugin:@typescript-eslint/recommended",
        "plugin:prettier/recommended",
    ],
    rules: {
        "sort-imports": "off",
        "@typescript-eslint/no-namespace": "off",
        "@typescript-eslint/ban-ts-comment": "off",
        "simple-import-sort/imports": "error",
        "simple-import-sort/exports": "error",
        "no-unused-vars": "off",
        "unused-imports/no-unused-imports": "error",
        "@typescript-eslint/no-var-requires": "warn",
        "@typescript-eslint/no-empty-function": "warn",
        "@typescript-eslint/ban-types": "warn",
        "unused-imports/no-unused-vars": [
            "warn",
            { vars: "all", varsIgnorePattern: "^_", args: "after-used", argsIgnorePattern: "^_" },
        ],
        eqeqeq: ["error", "smart"],
    },
    overrides: [
        {
            files: ["*.js"],
            rules: {
                "no-undef": "off",
            },
        },
    ],
};

Also, not sure why do I get 2 different outputs locally and in GitHub?
I ran yarn install locally and workflow is running it as well, so that shouldn’t be a different dependency versions issue. How can I fix this?

13

  • Node.js may run different versions of eslint or
    TypeScript. In your workflow file, node-version: is specified as
    20.x. You can check this
  • The caches used in GitHub Actions can cause problems. You can check this too.
  • As last you can compare the versions installed in both environments using the yarn list --pattern eslint command.

I may provide you one more thing that I using everytime is; eslint config

"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_", "ignoreRestSiblings": true, "caughtErrorsIgnorePattern": "^_", "ignoreRestSiblings": true, "destructuredArrayIgnorePattern": "^_", "ignoreTypeReferences": true }]

As mentioned in the comments, you can make sure that the packages are installed properly

Make sure that the dependencies are installed in the same way as in workflow by running the yarn install --immutable command.

I hope this helps you solve your problem.

New contributor

Ilker Ozturk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

try changing your type to

type STEPSTYPE = { [key in keyof Stepper]: number } | { [key in keyof CaseStepper]: number };

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật