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 with functions #53743

Closed
5 tasks done
kaaax0815 opened this issue Apr 11, 2023 · 3 comments
Closed
5 tasks done

satisfies with functions #53743

kaaax0815 opened this issue Apr 11, 2023 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@kaaax0815
Copy link

Suggestion

πŸ” Search Terms

satisifes, function

βœ… Viability Checklist

My suggestion meets these guidelines:

  • 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

satisifes keyword works with functions

πŸ“ƒ Motivating Example

type AllowedTypes = string | number | boolean | symbol | object | undefined | null;
type LoaderType = () => AllowedTypes;
type LoaderReturn = ReturnType<LoaderType>;

function loader1(): AllowedTypes {
  return 'anything';
}

const value1 = loader1();
//     ^? value1: AllowedTypes 

function loader2() {
  return 'anything';
} satisfies LoaderType

const value2 = loader2();
//     ^? value2: string 

function loader3() {
  loader1()
} satisfies LoaderType
// ^? error: () => void does not satisfy () => AllowedTypes 

πŸ’» Use Cases

In Libaries like Remix you have a loader which has to return something other than void. But there is no good method to check for that
This would check that you return anything, but the frontend is still able to infer what types are returned

@MartinJohns
Copy link
Contributor

Sounds like a duplicate of #52902.

@kaaax0815
Copy link
Author

yes this only extends it with arrow functions and the already existing satisfies keyword

@IllusionMH
Copy link
Contributor

Looks more like duplicate of #51556

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Apr 12, 2023
@kaaax0815 kaaax0815 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants