False Positive on typescript:S6759 when mixing interfaces and types

  • What language is this for? TypeScript
  • Which rule? typescript:S6759
  • Why do you believe it’s a false-positive/false-negative? All properties are defined as readonly, but it is being reported as not readonly
  • Are you using
    • SonarQube Cloud
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
export type PropsWithClassName<Props extends Record<string, unknown> = {}> = Readonly<
  Props & {
    className?: string;
  }
>;

export interface ContentRendererProps<Content extends ChatMessageContent = ChatMessageContent>
  extends PropsWithClassName {
  readonly chatId: string;
  readonly content: Content;
  readonly links?: LinkMessageContent[];
  readonly section: SectionResponseContent | ClientSideStreamSectionStartContent;
  readonly submissionId: string;
  readonly visible?: boolean;
}

// Error reported on following line: "Mark the props of the component as read-only."
function ErrorRenderer({ content }: ContentRendererProps<ErrorMessageContent>) {

Hi @landisdesign,

Thank you for the detailed report! This is indeed a false positive. The props are already effectively read-only in this typing pattern, but the rule does not recognize it correctly.

We’ve created JS-1685 to track the fix.

Thanks again for taking the time to report this, feedback like yours helps us improve the tool!
François

Thank you very much!

Regards,

Michael