Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeScript types #163

Closed
maranomynet opened this issue Apr 4, 2024 · 7 comments · Fixed by #164
Closed

Add TypeScript types #163

maranomynet opened this issue Apr 4, 2024 · 7 comments · Fixed by #164
Labels
help wanted Extra attention is needed

Comments

@maranomynet
Copy link

Any chance of an upgrade with support for newer versions of ESLint?

@lydell
Copy link
Owner

lydell commented Apr 4, 2024

Hi! I’m curious, why do you ask this?

@maranomynet
Copy link
Author

maranomynet commented Apr 4, 2024

I'm exploring converting my eslint (v8.57) config to use the new eslint.config.js "flat config" (like so):

// @ts-check
import simpleImportSort from 'eslint-plugin-simple-import-sort';

/** @type {Array<import('eslint').Linter.FlatConfig>} */
export default [
  // ...other configs...
  {
    plugins: {
      'simple-import-sort': simpleImportSort,
    },
    rules: {
      'simple-import-sort/exports': 'warn',
      // ...other rules
    }
  }
]

…and I get this TS error:

image

This sort of error is indicates that the plugin has to be updated.

@maranomynet
Copy link
Author

Does this make sense, or am I making some silly mistake?

@lydell
Copy link
Owner

lydell commented Apr 4, 2024

Thanks! I was wondering, because I already updated the plugin for ESLint 9 in #155. (To be extra clear, the plugin already worked with ESLint 9 and flat config, that PR just added an extra meta property and docs.)

The only thing I’m missing for “best in class flat config support” is types (see eslint/eslint#18093). I’ve only tested with plain JS, never TypeScript. I haven’t learned the best way to type an ESLint plugin yet.

In the code you posted there are a couple of errors:

  1. You import eslint-plubin-import-sort, but the actual name is eslint-plugin-simple-import-sort.
  2. You try to reference simpleIimportSort which is not defined.

However, the type errors in the screenshot seem to indicate other errors. I can’t tell from the information you provided what’s going on. I would have expected errors about eslint-plugin-simple-import-sort not providing any types if anything.

Either way, until I have added types to the package (or someone else has contributed them), you should be able to @ts-ignore (or similar) TypeScript errors and it should still work (as long as you’ve done everything correctly – see the README for examples).

@maranomynet
Copy link
Author

Yeah, so much for my ability to rapidly type in rough code
examples.😅.

Great to know that I can just ignore the errors. Thanks!

@lydell lydell changed the title Support ESLint v9 and "flat config" Add TypeScript types Apr 4, 2024
@lydell lydell added the help wanted Extra attention is needed label Apr 4, 2024
@maranomynet
Copy link
Author

I guess that as a quick and dirty solution you could do something like asserting that your exported rules are of type Linter.FlatConfig['plugins']['rules'] etc. ...without actually digging further into what the actual differernce is

@Logicer16 Logicer16 mentioned this issue Apr 6, 2024
@lydell
Copy link
Owner

lydell commented Apr 13, 2024

Version 12.1.0 has just been released with TypeScript types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants