-
-
Notifications
You must be signed in to change notification settings - Fork 299
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 compile errors #59
Comments
@adventmedia Would you test this with notistack |
I assume you meant |
@adventmedia Yes that was a typo. It's weird that it's happening even with |
unfortunately not at liberty to share the code. Typescript version is 3.2.2 in case that's relevant. |
Added typescript version to the issue. Will leave this open for a while in case other people wanted to report the same issue. |
I ran into the same issue and am currently using Here is the tslint error and hint:
|
Hi @iamhosseindhv . Faced the same problem but when using JS.
Thus, in a class where you need to call a snackbar, you need to add
But when I call a mutation to get a session and user, it causes an endless loop. Version 0.4.1 works perfect. What have you changed in the new version? Perhaps withSnackbar logic has changed? UPDATE.As far as I saw you add closeSnackbar property to withSnackbar component in 0.4.2. I don't understand why I need a method closeSnackbar. Could you tell something about this situation? |
@AlexanderVishnevsky I don't have enough info to find the issue in the problem you described. Maybe you (or other people facing this issue) could reproduce the error and provide a sandbox example? |
Dealing with this same error AND I'm also using functional components instead of class-based, as mentioned here: #29 Here's my TS code, which includes how I've temporarily solved the "use import React from 'react';
import { createStyles, withStyles } from '@material-ui/core/styles';
import { withSnackbar } from 'notistack';
import CssBaseline from '@material-ui/core/CssBaseline';
import Header from './Header';
import Sidebar from './Sidebar';
interface Theme {
mixins: {
toolbar: any;
};
spacing: {
unit: number;
};
}
const styles = (theme: Theme) =>
createStyles({
root: {
display: 'flex',
},
content: {
flexGrow: 1,
padding: theme.spacing.unit * 3,
},
toolbar: theme.mixins.toolbar,
});
interface Props {
classes: {
root: string;
toolbar: string;
content: string;
};
enqueueSnackbar: any;
}
const fetchFakeData = (enqueueSnackbar: (arg0: string) => boolean) => {
enqueueSnackbar('Success?');
};
const AppLayoutContainer = (props: Props) => {
const { classes, enqueueSnackbar } = props;
return (
<div className={classes.root}>
<CssBaseline />
<Header />
<Sidebar />
<div className={classes.content}>
<div className={classes.toolbar} />
<a onClick={() => fetchFakeData(enqueueSnackbar)}>Test</a>
</div>
</div>
);
};
export default withStyles(styles)(withSnackbar(AppLayoutContainer)); If I change this line:
to
then everything works ... but I'd really like to actually use a TS interface rather than relying on |
Thanks @cwbuecheler. @AlexanderVishnevsky mentioned that his issue is only appearing in |
@iamhosseindhv - Hmmm. Nope, I'm getting the error with
It is very possible that I'm not building my Interface correctly as I'm fairly new to TypeScript. :) |
Alright then we'll continue keeping the issue open for more info or ideally some |
Thanks. If I have a chance this weekend I'll try to get something up in a sandbox. Swamped today! |
I believe I found a solution for this. Essentially, you have to import the import React from 'react';
import { RouteComponentProps } from 'react-router-dom';
import { Typography } from '@material-ui/core';
import { withSnackbar, InjectedNotistackProps } from 'notistack';
import { Foo } from './Foo';
import FooForm from './FooForm';
import { CreateFooMutation, CREATE_FOO } from './CreateFooMutation';
import { FIND_FOOS } from './FindFoosQuery';
interface Props {
match: {
params: {
id: string;
};
};
}
type FinalProps = RouteComponentProps & Props & InjectedNotistackProps;
class CreateFoo extends React.Component<FinalProps> {
render() {
const {
match: {
params: { id },
},
enqueueSnackbar,
} = this.props;
return (
<>
<Typography variant="h1">Create Foo</Typography>
<CreateFooMutation
mutation={CREATE_FOO}
refetchQueries={[{ query: FIND_FOOS }]}
>
{(createFoo, { loading, error }) => {
return (
<FooForm
initialValues={{ foo: { title: '' } }}
onSubmit={async (values, actions) => {
try {
await createFoo({
variables: { foo: values.foo as Foo },
});
} finally {
actions.setSubmitting(false);
enqueueSnackbar('Success!');
}
}}
loading={loading}
error={error ? error.message : undefined}
/>
);
}}
</CreateFooMutation>
</>
);
}
}
export default withSnackbar(CreateFoo); The important line is this one: type FinalProps = RouteComponentProps & Props & InjectedNotistackProps; Where we're combining the If you're nesting Higher Order Components (eg: |
@cwbuecheler in that case I'll have to rename Would be nice if other people who have this issue could confirm the solution. |
@iamhosseindhv In my case, the problem was solved by rewriting the mutation from the imperative style to the declarative.
new version:
So, those manipulations do the trick. Works fine with |
This worked for me. Extend interface ForgotPasswordDialogProps extends RootState, InjectedNotistackProps {} |
Be aware |
This works, maybe this will help someone :) import { withStyles } from '@material-ui/core';
import { withSnackbar } from 'notistack';
import { withSnackbarProps } from 'notistack';
const styles = ({ palette, spacing }: Theme) => createStyles({
div: {
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
},
margin: {
margin: 30,
},
title: {
marginTop: 50,
},
footer: {
textAlign: 'center',
marginTop: 25,
marginBottom: 100,
},
});
interface IProps extends WithStyles<typeof styles>, withSnackbarProps { }
class LoginPage extends Component<IProps, {}> {
public state = {
submit: '',
key: '',
};
constructor(props: IProps) {
super(props);
}
public render() {
return (
<div>
</div>
);
}
}
export default withStyles(styles)(withSnackbar(LoginPage)); |
import { WithSnackbarProps, withSnackbar } from 'notistack' This worked for me in ^0.9.5 release. notice case |
export default withSnackbar(Chat)
throws this error when compiled:
Type error: Argument of type 'typeof Chat' is not assignable to parameter of type 'ComponentType<InjectedNotistackProps>'.
The text was updated successfully, but these errors were encountered: