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

Type error for flat configs with typescript-eslint's .config helper #181

Open
drasern opened this issue Nov 12, 2024 · 0 comments
Open

Type error for flat configs with typescript-eslint's .config helper #181

drasern opened this issue Nov 12, 2024 · 0 comments

Comments

@drasern
Copy link

drasern commented Nov 12, 2024

Describe the bug
A type error is thrown when using the typescript-eslint config() helper function to provide type checking for the "flat/recommended" config.

The code:

import tseslint from "typescript-eslint";
import storybook from "eslint-plugin-storybook";

export default tseslint.config(
  ...storybook.configs["flat/recommended"],
);

Versions:

    "eslint-plugin-storybook": "^0.11.0",
    "eslint": "^9.14.0",
    "typescript": "^5.6.3",
    "typescript-eslint": "^8.14.0",

The error:

Argument type
{name: string, plugins: {readonly storybook: any}, files?: undefined, rules?: undefined} | {name: string, files: string[], rules: {"react-hooks/rules-of-hooks": string, "import/no-anonymous-default-export": string, "storybook/await-interactions": string, "storybook/context-in-play-function": string, "storybook/default-exports": string, "storybook/hierarchy-separator": string, "storybook/no-redundant-story-name": string, "storybook/prefer-pascal-case": string, "storybook/story-exports": string, "storybook/use-storybook-expect": string, "storybook/use-storybook-testing-library": string, ...}, plugins?: undefined} | {name: string, files: string[], rules: {"storybook/no-uninstalled-addons": string, "react-hooks/rules-of-hooks"?: undefined, "import/no-anonymous-default-export"?: undefined, "storybook/await-interactions"?: undefined, "storybook/context-in-play-function"?: undefined, "storybook/default-exports"?: undefined, "storybook/hierarchy-separator"?: undefined, "storybook/no-redundant-story-name"?: undefined, "storybook/prefer-pascal-case"?: undefined, "storybook/story-exports"?: undefined, "storybook/use-storybook-expect"?: undefined, ...}, plugins?: undefined}
is not assignable to parameter type ConfigWithExtends ...   Type string is not assignable to type
Record<string, 0 | 1 | 2 | "error" | "off" | "warn" | [0 | 1 | 2 | "error" | "off" | "warn", ...unknown[]]>[string] | undefined
     Type string is not assignable to type
0 | 1 | 2 | "error" | "off" | "warn" | [0 | 1 | 2 | "error" | "off" | "warn", ...unknown[]]

This is because the declared type for each rule is the wide string instead of the more specific "error" | "off" | "warn" that the config is expecting.

To Reproduce
Steps to reproduce the behavior:

  1. Install eslint-plugin-storybook and typescript-eslint
  2. Wrap your esling.config.js in the config() helper function
  3. See error

Expected behavior
The declared type should match the acceptible possible values for the rules.

Additional context
The actual values of the strings in the config are correct, but the type definition file is widened to string.

ethanwu10 added a commit to ethanwu10/eslint-plugin-storybook that referenced this issue Nov 15, 2024
By using `as const` on the string values for each of the rule configs,
we ensure that the generated rules have string literal types matching
their configured values.

Fixes storybookjs#181
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant