-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
Support "satisfies" operator in type/interface declaration as well #53238
Comments
Sounds like a duplicate of #52222. |
|
Moreover, if the Basically, you are not able to enforce the But thanks a lot for commenting. |
@MartinJohns I did check that issue before posting here. Basically, 52222 is not highlighting exactly what I wanted to convey even though the title of the ticket is similar. Hence I create a separate issue highlighting the exact intent. Thanks for commenting. |
If that doesn’t error, then |
Nevermind, that doesn't work. I could have sworn it did. |
@fatcerberus "satisfies" does work normally for JS objects where every key in the object has to satisfy the "satisfies" clause. Interface should also work like that and hence my "issue" here to make it available on type/interface as well |
@abaldawa Yeah, I thought you could already use |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Suggestion
Currently "satisfies" operator only supports validating runtime const JS objects. It is SUPER useful and I have used it at so many places which has strongly typed the code base even further, thanks a lot for introducing this.
It would be very useful to also support "satisfies" operator in typescript type/interface declaration as well for exactly the same reasons.
🔍 Search Terms
satisfies, interface, type
✅ Viability Checklist
My suggestion meets these guidelines:
📃 Motivating Example
Currently "satisfies" operator is only supported in const runtime objects so that they retain their original definition but also have to satisfy the type constraint at either key or values or both.
It would be very helpful to also support the "satisfies" operator in TS interface/type for the very same reason without changing the definition of original interface/type.
See below use case.
💻 Use Cases
If we have an interface as below:
Now, if we want to derive a new interface that "satisfies" all the keys from the above interface but with different values, there is no way to express it as "satisfies" operator does not support type/interface.
Any reason why satisfies is only supported on JS const objects but not in TS types? If it is also supported at type/interface then it would be super useful.
The text was updated successfully, but these errors were encountered: