From afbe9350deca55bb70807765a3a2bbad826c2121 Mon Sep 17 00:00:00 2001 From: Guz013 <43732358+Guz013@users.noreply.github.com> Date: Fri, 14 Jul 2023 15:55:15 -0300 Subject: [PATCH] fix: type errors of typescript-eslint --- packages/core/src/env.d.ts | 49 +++++++++++++++++++++++++++++++++++++- packages/core/src/index.js | 6 ----- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/packages/core/src/env.d.ts b/packages/core/src/env.d.ts index 865d8e4..470707e 100644 --- a/packages/core/src/env.d.ts +++ b/packages/core/src/env.d.ts @@ -1,5 +1,7 @@ +import type { ESLint, Linter } from 'eslint'; + /** - * @see {@link https://github.com/sindresorhus/globals} + * @see {@link https://github.com/sindresorhus/globals github repository} * @summary Global identifiers from different Javascript environments * --- * **Note:** @@ -20,3 +22,48 @@ declare module 'globals' { }; export default globals; } + +/** + * @see {@link https://www.npmjs.com/package/@typescript-eslint/eslint-plugin npm package} + * @summary An ESLint plugin which provides lint rules for TypeScript codebases. + * + * --- + * **Note:** Types in this project where overridden to be compatible with ESLint new flat + * config types. ESlint already has backwards compatibility for plugins not created in the + * new flat config. + */ +declare module '@typescript-eslint/eslint-plugin' { + interface typescriptEslintPlugin extends ESLint.Plugin { + configs: { + recommended: { + rules: Linter.RulesRecord + } + 'recommended-requiring-type-checking': { + rules: Linter.RulesRecord + } + 'eslint-recommended': { + rules: Linter.RulesRecord + } + strict: { + rules: Linter.RulesRecord + } + } + } + const plugin: typescriptEslintPlugin; + export default plugin; +} + +/** + * @see {@link https://www.npmjs.com/package/@typescript-eslint/parser npm package} + * @summary An ESLint parser which leverages TypeScript ESTree to allow for ESLint + * to lint TypeScript source code. + * + * --- + * **Note:** Types in this project where overridden to be compatible with ESLint new flat + * config types. ESlint already has backwards compatibility for parsers not created in the + * new flat config. + */ +declare module '@typescript-eslint/parser' { + const parser: Linter.ParserModule; + export default parser; +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 85bb70f..3b0a225 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -24,22 +24,16 @@ export function defineConfig(userConfig) { { files: ['**/*.js', '**/*.ts'], plugins: { - // @ts-expect-error The `@typescript-eslint/eslint-plugin` package doesn't export - // a correct type as default. But this still works because of backwards-compatibility of eslint. '@typescript-eslint': tsEslint, }, languageOptions: { sourceType: 'module', - // @ts-expect-error The `@typescript-eslint/parser` package doesn't export a correct type as default. - // (see `plugins['@typescript-eslint']` option/property error for more info) parser: tsParser, parserOptions: { project: userConfig.tsconfig, tsconfigRootDir: process.cwd(), }, }, - // @ts-expect-error The `@typescript-eslint/eslint-plugin` package doesn't export - // rules as `RulesRecord` type. rules: { ...tsEslint.configs.recommended.rules, ...tsEslint.configs['recommended-requiring-type-checking'].rules,