type-fest icon indicating copy to clipboard operation
type-fest copied to clipboard

Require parameters in functions

Open fregante opened this issue 2 years ago • 12 comments

TypeScript is too loose when accepting functions:

type Fn = (a: string) => string;

const fn: Fn = () => '🥲'
// This is fine.

https://www.typescriptlang.org/play?#code/C4TwDgpgBAYgdlAvFAFAQwFxQM7AE4CWcA5gJRIB8O+RxA3AFAMDGA9nLlAGZxbxKpyiKgHJAfBuAnXZFA

Do you think there's a way to enforce the usage of the a parameter?

I have a situation where a function should only be used if a is required; if a isn't used, it's pointless.

A native example would be this: There's no point in using .some() if you're not going to use the array value inside the callback.

[0,12,345].some(() => true)

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

fregante avatar Oct 09 '22 05:10 fregante