Skip to content
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

[docs] Polish Snackbar demos #15129

Merged
merged 3 commits into from
Mar 31, 2019
Merged

[docs] Polish Snackbar demos #15129

merged 3 commits into from
Mar 31, 2019

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Mar 31, 2019

Removes some unnecessary JS diffs created in #15087.

@eps1lon eps1lon added docs Improvements or additions to the documentation typescript labels Mar 31, 2019
@mui-pr-bot
Copy link

No bundle size changes comparing 2482d2b...0522726

Generated by 🚫 dangerJS against 0522726

@@ -74,7 +70,7 @@ class ConsecutiveSnackbars extends React.Component<Props, State> {

render() {
const { classes } = this.props;
const { messageInfo = {} as SnackbarMessage } = this.state;
const { messageInfo = {} as Partial<SnackbarMessage> } = this.state;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an unsafe cast. It allowed messageInfo.message.length while it might throw at runtime if the queue is empty.

@@ -27,6 +23,10 @@ class App extends React.Component<withSnackbarProps> {
}
}

(App as React.ComponentClass<withSnackbarProps>).propTypes = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite ugly but it's the pattern we use throughout the codebase. Allows separation of interface and implementation and doesn't block readability (usually what we're interested in first is render).

};
}
class DirectionSnackbar extends React.Component<{}, State> {
state: State = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generic argument in React.Component is required for correct setState type while the explicit annotation in the class field is required for correct types in this.state. Otherwise TypeScript will infer the apparent type ({ open: boolean }) which means this.state.Transition is access of a not existing key.

@eps1lon eps1lon merged commit f9e8cb2 into mui:next Mar 31, 2019
@eps1lon eps1lon deleted the docs/cleanup-snackbar branch March 31, 2019 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants