seasonedcc / composable-functions

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

Input and environment params become `any` if no schema is passed #115

Closed danielweinmann closed 10 months ago

danielweinmann commented 10 months ago
const foo = makeDomainFunction()(({ inputFoo }, { envFoo }) => {
  return inputFoo + envFoo
})

I would expect the code above to fail to type-check but it works because both input and environment are of type any. Is it possible to make them never when no schema is passed?

I just had an unexpected runtime error because I was destructuring a key from the environment but had forgotten to pass the env schema to makeDomainFunction.

diogob commented 10 months ago

The current runtime logic for no schemas is different for input and environment:

So the any on envFoo above jives with this notion, since descruturing from an unknown will yield you any (which should be a red flag on its own).

inputFoo however, should not have type-checked since it will take only undefined.

danielweinmann commented 10 months ago

What's the reasoning behind assuming Record<PropertyKey, unknown> for environments?

danielweinmann commented 10 months ago

I just ran some tests and the env is not being considered a record of unknown. Both the input and the env are being inferred as any.

danielweinmann commented 10 months ago

Ooops. I was on 2.0.0. On 2.4.0 both are inferred as unknown, which solves the problem 🎉