Skip to content

Satisfies does not work with const assertionΒ #51173

@steverep

Description

@steverep

Bug Report

πŸ”Ž Search Terms

satisfies, as const, literal

πŸ•— Version & Regression Information

  • This is a crash
  • I was unable to test this on prior versions because satisfies is new in 4.9.0 beta

⏯ Playground Link

Playground Link

πŸ’» Code

type Colors = "red" | "green" | "blue";
type RGB = readonly [red: number, green: number, blue: number];
type Palette = Readonly<Record<Colors, string| RGB>>;

const palette1 = {
    red: [255, 0, 0],
    green: "#00ff00",
blue: [0, 0, 255]   
    // Expect to pass but throws error
} satisfies Palette as const;

πŸ™ Actual behavior

Fails with error:

'const' assertions can only be applied to references to enum members, or string, number, boolean, array, or object literals.

πŸ™‚ Expected behavior

No error because it is a literal and satisfies should not change the type. Also, other type assertions work fine, so const should as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions