feat(types): make types on functions extend off the base classes generics #1268
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The goal here is to eventually allow a
withForm
component to accept "extending" forms, or those which are bigger then what they know about but do contain what they need.I suspect that even an alternative solution to
withForm
would still need those changes to work.While looking at the TS error that comes when trying this, I noticed that it was always about the types in the functions but never about the object attributes. So after some experimenting, it turns out that this fails:
While this works:
and still ensures that
firstName
is included on t2. The main idea is unlessprops.value
only extends T, TypeScript checks the equality both ways. If it does extend T, the checking becomes unidirectional.This obviously still needs a lot of work to be done as most likely all function signatures would have to be changed in such a matter and more type errors will come up along the way.
But at least this works to prove the concept:
with surprisingly few errors in
FieldApi.ts
to track down.Once its all the way done, the inference should still work just fine.