Skip to content

satisfies operator changes the type of an expression #55189

Closed
@rimunroe

Description

@rimunroe

Bug Report

Applying the satisfies operator to an expression can change the type of that expression.

The release notes for the satisfies operator say the following:

The new satisfies operator lets us validate that the type of an expression matches some type, without changing the resulting type of that expression.

However, the type of the expression appears to be affected by the use of the operator.

This seems possibly related to #52394

🔎 Search Terms

satisfies, changes type, declaration

🕗 Version & Regression Information

Found in

  • 4.9.5
  • 5.0.4
  • 5.1.6
  • 5.2.0-beta

This is the behavior in every version I tried, and I reviewed the FAQ for any entries related to declarations, expressions, narrowing, etc. and couldn't find anything

⏯ Playground Link

Playground link with relevant code

💻 Code

type Foo = { a: boolean; }

const f = {a: true};
f.a = false; // no problem!

const g = {a: true} satisfies Foo;
g.a = false; // uh oh
//^ Type 'false' is not assignable to type 'true'.

🙁 Actual behavior

The type of g is { a: true; } when satisfies Foo is used, and { a: boolean; } if it's omitted.

🙂 Expected behavior

The type of g is { a: boolean; } regardless of whether satisfies Foo is used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions