Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Satisfies operator affects type inference for Symbol #61070

Open
yoshi-pi opened this issue Jan 29, 2025 · 3 comments Β· May be fixed by #61071
Open

Satisfies operator affects type inference for Symbol #61070

yoshi-pi opened this issue Jan 29, 2025 · 3 comments Β· May be fixed by #61071
Labels
Not a Defect This behavior is one of several equally-correct options

Comments

@yoshi-pi
Copy link

yoshi-pi commented Jan 29, 2025

πŸ”Ž Search Terms

"Symbol", "satisfies", "type inference"

πŸ•— Version & Regression Information

  • This changed between versions v4.9 and latest

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAZiEMC8MDKBPAtgIxAGwAoBKAbhgHoKYAVACwFMYoMAHJkOeRGASwmZsGnbiABQoSLBwBDAE4p02PEWIwIMqPzi8GAiMoLkqtRoPYwRshf3WH8QA

πŸ’» Code

const foo = Symbol(); // The type of foo is typeof foo
const bar = Symbol() satisfies symbol; // The type of bar is symbol

πŸ™ Actual behavior

Using the satisfies operator with Symbol changes the type of bar to symbol, instead of typeof foo.

πŸ™‚ Expected behavior

I expected the satisfies operator to have no effect on type inference, so bar should have the type typeof bar.

Additional information about the issue

No response

@RyanCavanaugh
Copy link
Member

I'm trying to figure out why you would ever write this code in the first place. Is there a more realistic repro?

@Andarist
Copy link
Contributor

Since I created a PR to "fix" this - I also don't see why one would like to write this but it looks like satisfies is changing the type of its operand here and that's something that satisfies, on principle, shouldn't do. So I just decided to open a PR for this since it was a one-line change anyway.

@yoshi-pi
Copy link
Author

yoshi-pi commented Jan 29, 2025

I simply discovered this problem and was curious to know whether it's a bug or intentional, so I opened an issue.

@RyanCavanaugh RyanCavanaugh added the Not a Defect This behavior is one of several equally-correct options label Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Not a Defect This behavior is one of several equally-correct options
Projects
None yet
3 participants