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

prefer-immutable-types: upgrade from v5 to v6 introduces an infinite recursion issue #733

Closed
danielnixon opened this issue Sep 4, 2023 · 3 comments
Labels
Status: Investigation Needed Issue need to be investigated further. Type: Bug Inconsistencies or issues which will cause a problem for users or implementors.

Comments

@danielnixon
Copy link

Bug Report

Hi, me again with another recursion issue :P

export type ReadonlyURLSearchParams = Readonly<
  OmitStrict<URLSearchParams, "append" | "delete" | "set" | "sort" | "forEach">
>;

// explosion here
export const readonlyURLSearchParams = (
  // eslint-disable-next-line functional/prefer-immutable-types
  init?:
    | readonly (readonly string[])[]
    // eslint-disable-next-line functional/prefer-readonly-type
    | string[][]
    | Record<string, string>
    | string
    | URLSearchParams
    | ReadonlyURLSearchParams,
): ReadonlyURLSearchParams =>
  new URLSearchParams(
    // eslint-disable-next-line @typescript-eslint/consistent-type-assertions, functional/prefer-readonly-type
    init as string[][] | Record<string, string> | string | URLSearchParams,
  );

export type ReadonlyURL = Readonly<OmitStrict<URL, "searchParams">> & {
  readonly searchParams: ReadonlyURLSearchParams;
};

Expected behavior

Linting terminates.

Actual behavior

Stack overflow:

❯ yarn lint 
yarn run v1.22.19
$ eslint src --ext .ts,.tsx --report-unused-disable-directives

Oops! Something went wrong! :(

ESLint: 8.48.0

RangeError: Maximum call stack size exceeded
Occurred while linting /Users/danielnixon/dev/agile-digital/readonly-types/src/index.ts:329
Rule: "functional/prefer-immutable-types"
    at /Users/danielnixon/dev/agile-digital/readonly-types/node_modules/eslint-plugin-functional/node_modules/is-immutable-type/dist/index.cjs:245:51
    at Array.map (<anonymous>)
    at typeArgumentsToString (/Users/danielnixon/dev/agile-digital/readonly-types/node_modules/eslint-plugin-functional/node_modules/is-immutable-type/dist/index.cjs:245:47)
    at TypeName.getNameWithArguments (/Users/danielnixon/dev/agile-digital/readonly-types/node_modules/eslint-plugin-functional/node_modules/is-immutable-type/dist/index.cjs:171:54)
    at /Users/danielnixon/dev/agile-digital/readonly-types/node_modules/eslint-plugin-functional/node_modules/is-immutable-type/dist/index.cjs:253:26
    at Array.map (<anonymous>)
    at typeArgumentsToString (/Users/danielnixon/dev/agile-digital/readonly-types/node_modules/eslint-plugin-functional/node_modules/is-immutable-type/dist/index.cjs:245:47)
    at TypeName.getNameWithArguments (/Users/danielnixon/dev/agile-digital/readonly-types/node_modules/eslint-plugin-functional/node_modules/is-immutable-type/dist/index.cjs:171:54)
    at /Users/danielnixon/dev/agile-digital/readonly-types/node_modules/eslint-plugin-functional/node_modules/is-immutable-type/dist/index.cjs:253:26
    at Array.map (<anonymous>)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Steps to reproduce

See example code above.

Proposed changes

@danielnixon danielnixon added Status: Triage This issue needs to be triaged. Type: Bug Inconsistencies or issues which will cause a problem for users or implementors. labels Sep 4, 2023
@danielnixon
Copy link
Author

@RebeccaStevens RebeccaStevens added Status: Investigation Needed Issue need to be investigated further. and removed Status: Triage This issue needs to be triaged. labels Sep 6, 2023
@ElPrudi
Copy link

ElPrudi commented Sep 17, 2023

Version 6.0.0 somehow doesn't like this nested array signature type[][]. Mine also got into infinite recursion after encountering this sort of type.

@RebeccaStevens
Copy link
Collaborator

Should hopefully now be fixed.

#767

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Investigation Needed Issue need to be investigated further. Type: Bug Inconsistencies or issues which will cause a problem for users or implementors.
Projects
None yet
Development

No branches or pull requests

3 participants