-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[typescript] Constrain props type param appropriately in withStyles, withTheme, withWidth HOCs #11003
Merged
Merged
[typescript] Constrain props type param appropriately in withStyles, withTheme, withWidth HOCs #11003
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e1f809d
Rewrite withStyles definition, using Omit
estaub f488adf
Fix test issues; redesign withTheme, withWidth using Omit also.
3560ac0
Use preferred style in tests
8eb517a
Remove another inferrable generic parameter from test.
175fa49
Remove another inferrable generic parameter from test.
92bee1b
Make inclusion of WithStyles in the innerComponent's type def optional.
c01d787
Commit for review and suggestions; DOES NOT COMPILE.
89d2a60
Redefine with* to remove Omit.
bcbf701
Bring back explicit generic parameter on union case in test, doc.
9fbbbc1
Rename withMyStyles back to decorate.
e66b8ea
Add trailing comma to function params in styling-comparison test.
0b47fb3
Fix package.json, yarn.lock.
748af39
Remove newline from typescript doc.
b24250b
Remove needless Omit imports.
ac934c1
Remove extra explicit from doc, add trailing semicolon to function
f1dbf16
Merge branch 'v1-beta' of https://github.com/mui-org/material-ui into…
ea20df9
Remove comment from styling-comparison.spec.tsx
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ const DecoratedClass = decorate( | |
}, | ||
); | ||
|
||
const DecoratedNoProps = decorate<{}>( | ||
const DecoratedNoProps = decorate( | ||
class extends React.Component<WithStyles<'root'>> { | ||
render() { | ||
return <Typography classes={this.props.classes}>Hello, World!</Typography>; | ||
|
@@ -46,3 +46,33 @@ const DecoratedNoProps = decorate<{}>( | |
const sfcElem = <DecoratedSFC text="Hello, World!" variant="title" color="secondary" />; | ||
const classElem = <DecoratedClass text="Hello, World!" variant="title" color="secondary" />; | ||
const noPropsElem = <DecoratedNoProps />; | ||
|
||
// This is the "scenario 2" example straight from the doc, then invoked: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no scenario 2 now, maybe just provide a link or else delete the comment. |
||
|
||
interface Book { | ||
category: 'book'; | ||
author: string; | ||
} | ||
|
||
interface Painting { | ||
category: 'painting'; | ||
artist: string; | ||
} | ||
|
||
type ArtProps = Book | Painting; | ||
|
||
const DecoratedUnionProps = decorate<ArtProps>( // <-- without the type argument, we'd get a compiler error! | ||
class extends React.Component<ArtProps & WithStyles<'root'>> { | ||
render() { | ||
const props = this.props; | ||
return ( | ||
<Typography classes={props.classes}> | ||
{props.category === 'book' ? props.author : props.artist} | ||
</Typography> | ||
); | ||
} | ||
}, | ||
); | ||
|
||
const unionPropElem = <DecoratedUnionProps category="book" author="Twain, Mark" />; | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion of the second (now only) scenario needs to be restored here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think not, if the compiler version can be moved forward. See below.