-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript
Description
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
π» 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.
tjx666, thorn0, ravshansbox, terrymun, insyri and 19 moreondratra, kenberkeley and mkosir
Metadata
Metadata
Assignees
Labels
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript