I am working on a class called Snackbar
that consists of various properties and methods. Here is an example:
export class SnackbarComponent {
optionA: number;
option2: string;
method1(){}
}
My goal is to include the properties
as keys in the options. I tried using
[I in SnackbarComponent]: SnackbarComponent[I];
, but encountered the following errors:
- A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type.ts(1170)
- A computed property name must be of type 'string', 'number', 'symbol', or 'any'.ts(2464)
- Cannot find name 'I'.ts(2304)
- Type 'any' cannot be used as an index type.ts(2538)
export class SnackbarService {
show(message: string, options?: {
randomString: string;
[I in SnackbarComponent]: SnackbarComponent[I];
}): Snackbar {
// Create instance of SnackbarComponent
// Set the properties on the SnackbarComponent
}
}