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

💅 lint/suspicious/noRedeclare false positive when using inline type signature on const with [key in MyMapPb[keyof MyMapPb]] #953

Closed
1 task done
valters opened this issue Nov 29, 2023 · 0 comments · Fixed by #958
Assignees
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@valters
Copy link

valters commented Nov 29, 2023

Environment information

We have a pattern of mapping enums to-from one system to another with the nice in ... keyof pattern. Biome considers these placeholder key syntax a variable redeclaration.
Like this:

export const MyMappingPbToGql: {
  [key in MyStatusMapPb[keyof MyStatusMapPb]]: StatusGql;
} = {
  [MyStatusPb.STATUS_INVALID]: StatusGql.Invalid,
  [MyStatusPb.STATUS_A]: StatusGql.A,
  [MyStatusPb.STATUS_B]: StatusGql.B,
  [MyStatusPb.STATUS_C]: StatusGql.C,
};

However when I have several of these enum to enum mappings, Biome complains.

Please see the code snippet in playground.

Biome shows error Shouldn't redeclare 'key'. Consider to delete it or rename it. But this is not correct. As far as I can tell whatever that 'key' signifies is not a reachable part of syntax.

Rule name

lint/suspicious/noRedeclare

Playground link

https://biomejs.dev/playground/?code=ZQB4AHAAbwByAHQAIABjAG8AbgBzAHQAIABNAHkATQBhAHAAcABpAG4AZwBQAGIAVABvAEcAcQBsADoAIAB7AAoAIAAgAFsAawBlAHkAIABpAG4AIABNAHkAUwB0AGEAdAB1AHMATQBhAHAAUABiAFsAawBlAHkAbwBmACAATQB5AFMAdABhAHQAdQBzAE0AYQBwAFAAYgBdAF0AOgAgAFMAdABhAHQAdQBzAEcAcQBsADsACgB9ACAAPQAgAHsACgAgACAAWwBNAHkAUwB0AGEAdAB1AHMAUABiAC4AUwBUAEEAVABVAFMAXwBJAE4AVgBBAEwASQBEAF0AOgAgAFMAdABhAHQAdQBzAEcAcQB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HQAdQBzAFAAYgAuAFMAVABBAFQAVQBTAF8ARgBdADoAIABPAHQAaABlAHIAUwB0AGEAdAB1AHMARwBxAGwALgBGACwACgB9ADsACgA%3D

Expected result

Linter should not complain about key being declared or redeclared. something in Map[keyof Map] in type signature is a special syntax and actually does not declare (or redeclare) anything.

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@Conaclos Conaclos added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug labels Nov 29, 2023
@Conaclos Conaclos self-assigned this Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants