Open
Description
Suggestion
π Search Terms
satisfies function
β Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
β Suggestion
Support the satisfies
operator to appear after a function
function foo () { } satisfies Bar
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.