Skip to content

Regression with TypeScript "as const" object literal in 2.0.3 #7956

@wincent

Description

@wincent

Playground hasn't updated to 2.0.3 yet, so this link was generated on 2.0.2 playground:

Prettier 2.0.2
Playground link

--parser typescript

Input:

const TYPE_MAP = {
    'character device': 'special',
    'character special file': 'special',
    directory: 'directory',
    'regular file': 'file',
    socket: 'socket',
    'symbolic link': 'link',
} as const;

Output:

const TYPE_MAP = {
  "character device": "special",
  "character special file": "special",
  directory: "directory",
  "regular file": "file",
  socket: "socket",
  "symbolic link": "link",
} as const;

Expected behavior:

The 2.0.2 behavior (above) is expected, but with 2.0.3, I get:

export const LOG_LEVEL =
    {
        EMERGENCY: 0,
        ALERT: 1,
        CRITICAL: 2,
        ERROR: 3,
        WARNING: 4,
        NOTICE: 5,
        INFO: 6,
        DEBUG: 7,
    } as const;

Only happens with as const qualifier. Without it, formatting continues to be like in 2.0.2:

export const LOG_LEVEL = {
    EMERGENCY: 0,
    ALERT: 1,
    CRITICAL: 2,
    ERROR: 3,
    WARNING: 4,
    NOTICE: 5,
    INFO: 6,
    DEBUG: 7,
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions