Repository navigation
Conversation
…ric instead of equal to them
Basically, this fails:
```ts
type Test<T> = {
defaultValues: T
fun: (props: { value: T }) => {}
}
const t: Test<{ firstName: string }> =
{} as Test<{ firstName: string, lastName: string }>
```
While this works:
```ts
type Test2<T> = {
defaultValues: T,
fun: <TF extends T = T>(props: { value: TF }) => void
}
// ist fine, the actual type has all that was asked for and then some
const t2: Test2<{ firstName: string }> =
{} as Test2<{ firstName: string, lastName: string }>
```
and still ensures that `firstName` is included on t2.
The main idea is unless `props.value` only extends T, TypeScript checks the equality both ways.
If it does extend T, the checking becomes unidirectional
harry-whorlow
marked this pull request as draft
March 12, 2025 11:10
Contributor
|
@s-hoff draft is more a type of pr than the title 🤟, just updated the pr for you |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
withFormcomponent 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
withFormwould 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
firstNameis included on t2. The main idea is unlessprops.valueonly 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.tsto track down.Once its all the way done, the inference should still work just fine.