Closed keichinger closed 5 years ago
With this change we must get rid of the type
parameter and ideally with the if
-parts in doMount
as well.
Also please target master
and branch of a master-v4
. master
is always the latest version.
Apparently GitHub has automatically closed my PR because I've renamed the master
branches. Well, I've opened a new PR #226 with the requested changes.
This PR splits the
mount
method up (again) into three distinct methods:mount
for mountingfunction
smountClass
for mountingStandaloneComponent
smountJsx
for mounting Preact components (functional and class)This change has sadly been necessary, as TypeScripts generic type inference couldn't support a new feature: automatic parameter inference/checking for the component you were trying to mount. In case there is no additional component parameters, the corresponding
mojave.*MountOptions::params
type will benever
, to enforce this as well.There is one caveat to this feature, which I'm not yet sure how to prevent/implement it right now, which is TypeScript isn't throwing any errors when I don't define the
options.params
property. However, this is a known limitation (for now) which I greatly accept as the new feature is better for overall DX and reduces the amount of accidental errors. Other than that, we're currently not throwing any errors as well, so this is not even a regression and thus should be fine.Here are a few examples of what's working and what is (currently) still not yet possible to support:
mount
withfunction
sExample component
mount
now is aware of the second, boolean parameter and correctly throws errors when too few or too many parameters have been passed. It extracts any additionalfunction
from the passed-in function and uses these as type formojave.FunctionMountOptions::params
:mountClass
withStandaloneComponent
Example component
Here, mounting
SomeMountableComponent
usingmountClass
works the same way asmount
does: It automatically extracts additional constructor parameters from the passed-inStandaloneComponent
, which is then used as type formojave.ClassMountOptions::params
to check against.mountJsx
with Preact componentsLast but not least:
The story here is very similar. The only difference, as previously, is that
mojave.ComponentMountOptions::params
's type is now the corresponding props-type of the given component. So in the case ofSomePreactFunctionalComponent
the type isPreactFunctionalProps
, forSomePreactClassComponent
it'sSomePreactClassComponentProps
.