I have a SnackBarService in which I expose a function:
public openSnackBar(message: string, state: SnackBarState, data?: any): void {
message = this.setMessageText(message, data);
this._snackBar.openFromComponent(SnackBarComponent, {
panelClass: state,
duration: 3500,
data: {
message: message,
state: state
} as SnackBarData
})
}
private setMessageText(message: string, data?: any): string {
switch (message) {
case 'U_03':
message = `Welcome back ${data.username}`
break;
}
return message
}
The data could be the return value of this Apollo mutation:
return this.apollo.mutate<LoginUser>({
mutation: LOGIN_USER,
variables: {
email: formData.email,
password: formData.password
}
})
The returned value from Apollo will always (at least I think) be a object containing data and a message:
{
data: User
message: String
}
{
data: Movie
message: String
}
So now I'm using data: any since the returned object can be of many types. I'm pretty sure I need to use TypeScript generics for this, but I would love a pointer in the right direction