Skip to content

quoteProps: "as-needed" strips quotes from 'new' method signature, changing it into a construct signature #19618

Description

@JSRossiter

Prettier v3.9.5
Playground link

--parser typescript

Input:

interface Container {
  'new'(id: string): number;
}

Output:

interface Container {
  new(id: string): number;
}

Expected output:

interface Container {
  'new'(id: string): number;
}

Why?

Unquoted new(...) in an interface/type is a construct signature, not a property named new, so as-needed should treat the quotes as required.

// Input (quoted) — compiles cleanly
interface Container { 'new'(id: string): number }
type K = keyof Container;   // "new"
type M = Container['new'];  // (id: string) => number
// Prettier's output (unquoted) — now errors
interface Container { new (id: string): number }
type K = keyof Container;   // never
type M = Container['new'];  // TS2339: Property 'new' does not exist on type 'Container'

#17694 is a similar issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedWe're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue!lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions