Skip to content

[isolatedDeclarations] explicit annotation required when satisfies T is provided on an object that would otherwise be inferrableΒ #61859

Closed as not planned
@bradzacher

Description

@bradzacher

πŸ”Ž Search Terms

isolatedDeclarations, "as const", "satisfies"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ

⏯ Playground Link

https://www.typescriptlang.org/play/?isolatedDeclarations=true#code/C4TwDgpgBAKlC8UDeUwCcD2YBcUDOwaAlgHYDmUAvgNwBQtEAHmBmsFAMYYkFTfSIktKKkw4oAcgkAaWjXpMWbTt17AA7hgTJhorLimzKUAIZ4VPYHVoB6G1AhpMac9gAUDZq3ZdLUYAAWaBACOiLo+pIycvgmwER4AGZEEOYw1nYOTqyuHoreFryJGACuaNpC4WIG0cZmhex4cQnJqbB0QA

πŸ’» Code

type T = { prop: string };

export const one = {
  prop: '',
};

export const two = {
  prop: '',
} as const;

// errors :(
export const three = {
  prop: '',
} satisfies T;

// errors :(
export const four = {
  prop: '',
} as const satisfies T;

πŸ™ Actual behavior

three and four both have errors, even though their satisfies-less counterparts do not have errors.

πŸ™‚ Expected behavior

all four variables should not error

Additional information about the issue

I guess that currently the presence of satisfies causes a different code path that ignores whether the underlying expression would be valid?
It would be good if TS was able to "look past" the satisfies so it can treat the code the same as if there was no satisfies.

This behaviour encourages you to do hacky things like this to "work around" the limitation.

export const three2 = {
  prop: '',
};
three2 satisfies T;

export const four2 = {
  prop: '',
} as const;
four2 satisfies T;

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions