Omnistac / zedux

:zap: A Molecular State Engine for React
https://Omnistac.github.io/zedux/
MIT License
376 stars 7 forks source link

fix: improve overloads of atom-template-accepting functions for paramless atoms #50

Closed bowheart closed 1 year ago

bowheart commented 1 year ago

Description

The ParamlessTemplate type helper is good enough in most situations, however there are some exceptions. Namely, when declaring a function that accepts only paramless atom templates (singletons) for simplicity reasons, the types don't "just work" and require an extra cast:

function noParams<A extends AnyAtomTemplate<{ Params: [] }>>(atom: A) {
  return myEcosystem.get(atom) // Error! Even though we know the params are `[]`
}

This PR fixes that. The above code will no longer error.

Affects

atoms, react