Skip to content

Commit

Permalink
Merge pull request #67 from eps1lon/patch-1
Browse files Browse the repository at this point in the history
Fix formatting, syntax, typos in Props helper
  • Loading branch information
swyxio authored Jan 14, 2019
2 parents 880f69a + 3928b4a commit 1bc63e0
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions ADVANCED.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,14 @@ The advantage of extracting the prop types is that you won't need to export ever
// helper type for all known valid JSX element constructors (class and function based)
type ElementConstructor<P> =
| ((props: P) => React.ReactElement<any> | null)
| (new (props: P) => React.Component<P, any, any>
| (new (props: P) => React.Component<P, any, any>);

// gets the internal props of a component
// used like Props<typeof MyComponent>
// or Props<'button'> for intrinsic HTML attributes
type Props<C> = C extends ElementConstructor<infer P>
? P
: C extends keyof JSX.IntrinsicElements
? JSX.InstrinsicElements[C]
: {}
: C extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[C] : {};

// goes one step further and resolves with propTypes and defaultProps properties
type ApparentProps<C> = C extends ElementConstructor<infer P> ? JSX.LibraryManagedAttributes<C, P> : Props<C>
Expand Down

0 comments on commit 1bc63e0

Please sign in to comment.