S4622 Picking keys while creating a type using Pick

  • What language is this for? TypeScript

  • Which rule? Union types should not have too many elements S4622

  • Why do you believe it’s a false-positive/false-negative?
    I believe this is a false positive because I am not doing a union of types, I am Pick keys to building a type

  • Are you using

    • SonarQube - 9.5
  • How can we reproduce the problem? Give us a self-contained snippet of code

type newType = Pick< Foo, "key1" | "key2" |  "key3" | "key4" | "key5" >

Hi @Moser-ss

Welcome and thank you for your feedback.
This issue appears here because Pick<Type, Keys> accepts a union of string literals for Keys, and S4622 targets a union with more than 3 types by default.
You can still avoid the issue by defining a new type for the union of the keys and using it in Pick.
You can also configure the rule to allow more elements than the default value of 3 if you feel it’s too low.

Hope it helps.