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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions