-
Notifications
You must be signed in to change notification settings - Fork 12.8k
satisfies
for return types
#59577
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
Comments
Duplicate of #51556. |
@MartinJohns i've seen that issue and i don't think the feature request is the same. #51556 seeks to be able to ensure that an entire function signature |
IMO that's a negligible difference. Both issues want the same: The function must satisfy a type. You just don't care about the arguments, so you'd check for But it's up to the maintainers to decide if it's a duplicate or not. |
The same request was made before: #52195
I would still really love to see this specific syntax to be accepted though π₯² |
funny enough, i also requested a proto-version of #52195 in #7481 (comment) before the tbh i still would absolutely love to see #52195 come to fruition, but maybe the scope/lift for #59577 is smaller and therefore more viable as an aside, i can see in #58918 (comment) and plenty of other feature requests there's a desire to co-opt |
Uh oh!
There was an error while loading. Please reload this page.
π Search Terms
satisfies
return
β Viability Checklist
β Suggestion
π Motivating Example
π» Use Cases
The
satisfies
operator has been immensely useful for ensuring expressions match some wider type while also inferring their narrower typeHowever, because
satisfies
works only on expressions, getting the same behavior on function return types requires workarounds with several drawbacks. For example, if a function has multiplereturn
values, we need to typesatisfies SomeType
for every single one of them, which is not only cumbersome but also prone to human errorplayground link
This style is also incompatible with codebases that prefer/require their contributors to declare the return type of their functions (e.g. through eslint)
Another workaround exists by using
satisfies
on the entire function:playground link
but having to parenthesize the entire function just to be able to operate on it as an expression and then include the function signature in the
satisfies
type is at best impractical and at worst not even an option, in the case offunction fn() { /* ... */ }
declarations. Of course, function declarations will be available as expressions after the declaration, at which pointsatisfies
can be used, but not to its full extent because the type-inference will no longer be able to guide the implementation of the function declaration from within the function bodyplayground link
Being able to specify that the return type of a function
satisfies
a type would resolve all of the above drawbacksThe text was updated successfully, but these errors were encountered: