You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support the satisfies operator to appear after a function
functionfoo(){}satisfiesBar
This was requested/mentioned in #47920 several times but never followed up on
π Motivating Example
satisfies is super handy to use, and you can already use it for arrow functions. Not having support for it on functions feels unintuitive and forces a certain coding style where people have to use arrow functions when they rather want to use functions.
π» Use Cases
Typing a function while preserving its return type.
It is not the prettiest way to define a function but it does the job and the result is awesome - retains the actual types and therefore infers the generic of SpotServicesController whereas if i just did const binance: SpotServicesController i would need to do const binance: SpotServicesController<BinanceTickerResult>
Not to mention the IDE tips become much less useless without jumping around to diff files to track down what the type is:
Weird that this didn't make it to 4.9 :/ Ryan Cavanaugh (@RyanCavanaugh) Sorry to tag you but just wanted to ask whether there's any chance this will be implemented in the near future? The satisfies feature just feels incomplete without it.
FUJI Goro (@gfx) the difference is that implements would require you to define the type of the parameters. But anyone goes, the current situation is quite annoying.
I was looking for this suggestion. Upvoted it immediately. The first time I had to write some pages with Next, I was just thinking that I would replace lambda by function (for all the benefits that function has over lambda) and thought that satisfies would just work better by not erasing the return type but keeping it type safe nonetheless. Really surprised that an exception for function has been made here.
It's such a recurring use case. It would be awesome to get it. Especially because it would be consistent with just all the others use cases where satisfies is valid. Please make it a reality! π
Reacted by Arad Alvand, SancheZz, Zuruh, Ilia Choly, ayame113 (val440), brettbedarfmw, Mon, cenuij, Luiz βFeldsβ Liscia, Jayden Seric and 13 more
Hey Ryan Cavanaugh (@RyanCavanaugh) could you provide any feedback on status of this topic? Maybe we could add any more feedback to raise its visibility in typescript's backlog?
Reacted by Ethan Resnick, Mon, Arad Alvand, Haltarys, Nikolai and Theodros Yimer
Guys, I'm subscribed to this issue so that I can see updates on its progress. The maintainers are aware of this issue and spamming in here is annoying for everyone involved. Unless you have something meaningful to add the to the conversation, please use the emoji reactions to indicate your support/interest.
Reacted by Josef KubΓΔek, poke, Mon, Simon H, Boris MuΓ±oz, Ryan Bogle, Nate Moore, Bruno Dienstmann Koch, Haltarys, Venyl and 89 more
Reacted by Leibale Eidelman, Tiago, Kræn Hansen and Jean Duthon
Yeah but then you have to type the parameter types again, it would be preferable to use satisfies only for the return type
At risk of stating the obvious, if the goal is strictly to declare the parameter type only once in this example (and in general) you can rely on inference from the satisfied type (similar to the return type):
Even if there are some slightly awkward ways to manage this with function expressions and arrow functions, it would be nice if there was a solution for function declarations, which seems to be the original ask.
Reacted by Alex Bok, Laurence Rowe, bgenia, LEE HYEONU, Maximilian FΓΆrster and snarbles2
all the solutions have downsides - added parenthesis, using a function expression / arrow function, having to double type the arguments, creating an anonymous function that isn't accessible in the same file (the above example).
We just want to be able to type a functions Params and return types in a single shot and have the values inferred. and satisfies would work?
typeRouteHandler<Textendsobject>=(body: T)=>Promise<Response>;asyncfunctionhandleRoute({ name }){returnnewResponse.json({message: `Hello ${name}`});}satisfiesRouteHandler<{name?: string}>
Reacted by Ian Luca, Ilia Choly, Thomas B Homburg, Alexey Maslennikov, Jan Stoots, Chris Carrick, Struan, Lucas Forster, Alvis Tang, Mark H and 22 more
Reacted by Caleb Jasik, Hannes Widrig, Laurence Rowe, Dana Woodman, bgenia, Guillaume Humbert, Thomas B Homburg, Michael Romanenko, Chris Carrick, Dennis Sen and 10 more
Yeah but then you have to type the parameter types again, it would be preferable to use satisfies only for the return type
At risk of stating the obvious, if the goal is strictly to declare the parameter type only once in this example (and in general) you can rely on inference from the satisfied type (similar to the return type):
I wouldn't say that's stating the obvious :) I didn't realize that satisfies on the whole function would make typescript infer the parameter inside the function, but when you mention it it's obvious that typescript needs to do this to ensure type safety.
I would still prefer the syntax of putting the satisfies keyword for the return type after the parameters, but this is semantically what I'm after. Thank you!
just noticed this isn't possible today - would be really helpful for an API I'm exposing to users if I could just export a function type they could use to both type check and type hint their own functions
Activity
bradennapier commentedon Nov 17, 2022
It is not the prettiest way to define a function but it does the job and the result is awesome - retains the actual types and therefore infers the generic of
SpotServicesControllerwhereas if i just didconst binance: SpotServicesControlleri would need to doconst binance: SpotServicesController<BinanceTickerResult>Not to mention the IDE tips become much less useless without jumping around to diff files to track down what the type is:
gfx commentedon Dec 5, 2022
This feature is absolutely useful for everyone, but there's already a feature request with
implementskeyword for the same purpose in 2019:xamir82 commentedon Dec 11, 2022
Weird that this didn't make it to 4.9 :/
Ryan Cavanaugh (@RyanCavanaugh) Sorry to tag you but just wanted to ask whether there's any chance this will be implemented in the near future? The
satisfiesfeature just feels incomplete without it.aradalvand commentedon Jan 4, 2023
This should've honestly been implemented already; such a bummer.
PooSham commentedon Feb 22, 2023
FUJI Goro (@gfx) the difference is that
implementswould require you to define the type of the parameters. But anyone goes, the current situation is quite annoying.ekaradon commentedon Mar 4, 2023
I was looking for this suggestion. Upvoted it immediately. The first time I had to write some pages with Next, I was just thinking that I would replace lambda by function (for all the benefits that function has over lambda) and thought that satisfies would just work better by not erasing the return type but keeping it type safe nonetheless. Really surprised that an exception for function has been made here.
It's such a recurring use case. It would be awesome to get it. Especially because it would be consistent with just all the others use cases where satisfies is valid. Please make it a reality! π
aradalvand commentedon Mar 4, 2023
Functions are possibly the most common use case for
satisfiesand they're not supported.Brilliant.
hanneswidrig commentedon Apr 19, 2023
What can we do to give this more visibility, I see "awaiting more feedback" is one of the tags on this issue?
maslennikov commentedon Jun 6, 2023
This is what I believe would be the most valuable use-case of
satisfiesfor memaslennikov commentedon Jun 17, 2023
Hey Ryan Cavanaugh (@RyanCavanaugh) could you provide any feedback on status of this topic? Maybe we could add any more feedback to raise its visibility in typescript's backlog?
mon-jai commentedon Jul 1, 2023
Bump
xamir82 commentedon Jul 2, 2023
Ryan Cavanaugh (@RyanCavanaugh) Could you look at this please.
icholy commentedon Jul 2, 2023
Guys, I'm subscribed to this issue so that I can see updates on its progress. The maintainers are aware of this issue and spamming in here is annoying for everyone involved. Unless you have something meaningful to add the to the conversation, please use the emoji reactions to indicate your support/interest.
lrowe commentedon Mar 1, 2024
This already seems to be supported so long as you add parentheses:
francescosalvi commentedon Mar 1, 2024
seems to works either way, but perhaps stylistically the closing parenthesis should go right before
satisfies?PooSham commentedon Mar 1, 2024
Yeah but then you have to type the parameter types again, it would be preferable to use satisfies only for the return type
alextbok commentedon Mar 1, 2024
At risk of stating the obvious, if the goal is strictly to declare the parameter type only once in this example (and in general) you can rely on inference from the satisfied type (similar to the return type):
snarbies commentedon Mar 1, 2024
Even if there are some slightly awkward ways to manage this with function expressions and arrow functions, it would be nice if there was a solution for function declarations, which seems to be the original ask.
wesbos commentedon Mar 1, 2024
all the solutions have downsides - added parenthesis, using a function expression / arrow function, having to double type the arguments, creating an anonymous function that isn't accessible in the same file (the above example).
We just want to be able to type a functions Params and return types in a single shot and have the values inferred. and satisfies would work?
PooSham commentedon Mar 13, 2024
I wouldn't say that's stating the obvious :) I didn't realize that satisfies on the whole function would make typescript infer the parameter inside the function, but when you mention it it's obvious that typescript needs to do this to ensure type safety.
I would still prefer the syntax of putting the satisfies keyword for the return type after the parameters, but this is semantically what I'm after. Thank you!
louwers commentedon Oct 6, 2024
If this is implemented, please don't forget about JSDoc.
Example
This currently works
This does not:
I think the title and description of this issue should be updated to say: allow
satisfieson function declarations.NatoBoram commentedon Oct 7, 2024
Related:
RebeccaStevens commentedon Apr 24, 2025
I think moving the
satisfieskeyword forward would make for easier readability.e.g.
mark-dr commentedon Apr 24, 2025
Rebecca Stevens (@RebeccaStevens) I think in that approach the readability would suffer if the type were anything non-trivial. e.g. imagine:
IMO, it creates too much distance between the function name and the parameter list.
marcospgp commentedon Jun 27, 2025
just noticed this isn't possible today - would be really helpful for an API I'm exposing to users if I could just export a function type they could use to both type check and type hint their own functions
rafa-br34 commentedon Jan 22, 2026
louwers commentedon Jan 22, 2026
lolmaus commentedon Jan 22, 2026