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

Effect.fn should preserve value of function's length property #4435

Closed
bwbuchanan opened this issue Feb 11, 2025 · 0 comments · Fixed by #4447 or #4434
Closed

Effect.fn should preserve value of function's length property #4435

bwbuchanan opened this issue Feb 11, 2025 · 0 comments · Fixed by #4447 or #4434
Labels
enhancement New feature or request

Comments

@bwbuchanan
Copy link

bwbuchanan commented Feb 11, 2025

What is the problem this feature would solve?

Currently, functions returned by Effect.fn have a length of 0. This means that consumers cannot accurately determine the number of arguments to the function.

This problem manifests with cucumber, which verifies that functions passed as step definitions have the expected number of arguments.

What is the feature you are proposing to solve the problem?

Effect.fn should use Object.defineProperty to set the length of the returned function to the value of body.length.

What alternatives have you considered?

I have an ugly workaround in the form of a wrapper function for Effect.fn.

const fn: typeof Effect.fn = function (nameOrBody: any, ...pipeables: any[]) {
  const argsCount = typeof nameOrBody === 'function' ? nameOrBody.length : pipeables[0].length;

  const newFn = Effect.fn(nameOrBody, ...pipeables);

  Object.defineProperty(newFn, 'length', { value: argsCount });

  return newFn;
} as any;

Configuring the length property of a Function is widely supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
1 participant