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

Accept immutable arrays within fromFixture #4

Closed
rafaelss95 opened this issue Oct 13, 2021 · 2 comments · Fixed by #6
Closed

Accept immutable arrays within fromFixture #4

rafaelss95 opened this issue Oct 13, 2021 · 2 comments · Fixed by #6

Comments

@rafaelss95
Copy link
Contributor

rafaelss95 commented Oct 13, 2021

Consider this scenario:

type MessageIds = ESLintUtils.InferMessageIdsTypeFromRule<typeof rule> // 'preferConcatLatestFrom'
type Options = ESLintUtils.InferOptionsTypeFromRule<typeof rule> // [{ readonly strict: boolean; }]

const valid: TSESLint.RunTests<MessageIds, Options>['valid'] = []
const invalid: TSESLint.RunTests<MessageIds, Options>['invalid'] = [
  fromFixture(``, {
    options: [{ strict: true }], // here I get the error described below
    output: ``,
  }),
]

Type 'InvalidTestCase<"preferConcatLatestFrom", { strict: boolean; }[]>' is not assignable to type 'InvalidTestCase<"preferConcatLatestFrom", Options>'.
Types of property 'options' are incompatible.
Type 'readonly { strict: boolean; }[]' is not assignable to type 'readonly [{ strict: boolean; }]'.
Target requires 1 element(s) but source may have fewer.ts(2322)

So, to fix this, I can either do options: [{ strict: true }] as const or { output: ..., options: ... } as const and so the TS is happy, however fromFixture doesn't accept readonly arrays...

I believe that it's a simple change:

- export declare function fromFixture<TMessageIds extends string, TOptions extends unknown[]>
+ export declare function fromFixture<TMessageIds extends string, TOptions extends readonly unknown[]>

and

- suggestions?: eslint.SuggestionOutput<string>[] | null | undefined;
+ suggestions?: readonly eslint.SuggestionOutput<string>[] | null | undefined;
- suggestions?: eslint.SuggestionOutput<TMessageIds>[] | null | undefined;
+ suggestions?: readonly eslint.SuggestionOutput<TMessageIds>[] | null | undefined;

Let me know if this case was clear enough to describe the issue (and I'm able to help submitting a PR if that's the case).

@cartant
Copy link
Owner

cartant commented Oct 13, 2021

Let me know if this case was clear enough to describe the issue (and I'm able to help submitting a PR if that's the case).

Sure. Open a PR if you have time.

@cartant
Copy link
Owner

cartant commented Oct 17, 2021

Closed by #6 and published as 4.2.6.

@cartant cartant closed this as completed Oct 17, 2021
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

Successfully merging a pull request may close this issue.

2 participants