Closed hyoban closed 8 months ago
I try to provide the type of rules using type calculation like below:
// eslint-define-config.d.ts
import type eslintPlugin from "./index";
type Rules = typeof eslintPlugin.rules;
declare module "eslint-define-config" {
export type CustomRuleOptions = {
[ruleName in keyof Rules as `@eslint-react/${ruleName}`]: Parameters<Rules[ruleName]["create"]>[0]["options"];
};
type A = CustomRuleOptions["@eslint-react/debug/class-component"];
// ^?
type B = CustomRuleOptions["@eslint-react/naming-convention/filename"];
// ^?
}
The type of A is calculated correctly to empty array:
type A = []
But the type of B is miscalculated as the union of the types of the options of the two rules.
type B = readonly [{
excepts?: readonly string[];
rule?: "kebab-case" | "camelCase" | "PascalCase" | "snake_case";
}?] | readonly [{
rule?: "always" | "as-needed";
}?]
The type of B should be
type B = readonly [{
excepts?: readonly string[];
rule?: "kebab-case" | "camelCase" | "PascalCase" | "snake_case";
}?]
I need your help @Rel1cx
Oh, I know why
https://github.com/eslint-types/eslint-define-config?tab=readme-ov-file#want-to-support-your-own-plugin