seasonedcc / composable-functions

Types and functions to make composition easy and safe
MIT License
649 stars 13 forks source link

applySchema does not accept plain functions #163

Closed danielweinmann closed 1 month ago

danielweinmann commented 1 month ago

I get the following error when trying to use applySchema with a plain function:

  const increment = (value: number) => value + 1
  const incrementWithSchema = applySchema(z.number())(increment)

// Argument of type '(value: number) => number' is not assignable to parameter of type '((input: number, context: unknown) => Promise<Result<unknown>>) & { kind: "composable"; }'.
//   Type '(value: number) => number' is not assignable to type '(input: number, context: unknown) => Promise<Result<unknown>>'.
//     Type 'number' is not assignable to type 'Promise<Result<unknown>>'.ts(2345)

If I wrap it with composable, everything works fine.

  const increment = composable((value: number) => value + 1)
  const incrementWithSchema = applySchema(z.number())(increment)
gustavoguichard commented 1 month ago

Yup, this is planned. And, once we do that, applySchema and withSchema will do the same thing. Use withSchema for plain functions in the meantime

gustavoguichard commented 1 month ago

@danielweinmann #164 should solve this issue =)

gustavoguichard commented 1 month ago

Solved on v4.3