fix(types): fix ExtractedValue type#4334
Merged
fb55 merged 2 commits intocheeriojs:mainfrom Feb 19, 2025
Merged
Conversation
Member
|
Thanks for this awesome PR! Could you add a types test to validate this works (and keeps working), using the same |
TypeScript does not automatically distribute conditionals unless the generic type itself represents a union. So, in `ExtractedValue`, `V['value']` is not distributed unless inferred as a separate generic type.
```
// Testing distributed conditional over an indexed access type
interface Obj {
value: string | number;
}
type TestIndexedObj<V extends { value: unknown }> = V['value'] extends number ? 'extends number' : 'does not extend number';
type TestIndexedObjResult = TestIndexedObj<Obj> // "does not extend number"
// Testing distributed conditional over a union
type ObjValue = Obj['value'];
type TestUnion<V> = V extends number ? 'extends number' : 'does not extend number';
type TestUnionResult = TestUnion<ObjValue> // "does not extend number" | "extends number"
// Testing distributed conditional over an inferred generic from an indexed access type
type TestInferredIndexedObj<V extends { value: unknown }> = V['value'] extends infer U ? (U extends number ? 'extends number' : 'does not extend number') : never;
type TestInferredIndexedObjResult = TestInferredIndexedObj<Obj> // "does not extend number" | "extends number"
```
b475416 to
12ea051
Compare
12ea051 to
5c4f05a
Compare
Contributor
Author
|
Apologies for the delay - added! |
1 task
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.
Noticed this while working with
extractTypeScript does not automatically distribute conditionals unless the generic type itself represents a union. So, in
ExtractedValue,V['value']is not distributed unless inferred as a separate generic type.EDIT: Adding issue link