-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #318 from Muritavo/feature/type_from_generics
Inferring type from constrained generics
- Loading branch information
Showing
3 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//In our case we have a component that works like the foolowing | ||
|
||
type SampleUnion = 'value 1' | 'value 2' | 'value 3' | 'value 4' | 'value n'; | ||
type SampleObject = { | ||
propA: string; | ||
propB: object; | ||
propC: number; | ||
}; | ||
class Base { | ||
propA: string = 'A'; | ||
} | ||
class SampleUnionNonGeneric extends Base { | ||
propB: string = 'B'; | ||
} | ||
|
||
export const GenericWithExtends = < | ||
G extends SampleUnion, | ||
A extends number[], | ||
O extends { prop1: number } | ||
>(props: { | ||
/** sampleUnionProp description */ | ||
sampleUnionProp: G; | ||
/** sampleUnionNonGeneric description */ | ||
sampleUnionNonGeneric: SampleUnionNonGeneric; | ||
/** sampleObjectProp description */ | ||
sampleObjectProp: SampleObject; | ||
/** sampleNumberProp description */ | ||
sampleNumberProp: number; | ||
/** sampleGenericArray description */ | ||
sampleGenericArray: A; | ||
/** sampleGenericObject description */ | ||
sampleGenericObject: O; | ||
/** sampleInlineObject description */ | ||
sampleInlineObject: { propA: string }; | ||
}) => { | ||
return <div>test</div>; | ||
}; |
This file contains 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
This file contains 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