on this piece of code
export interface Field {
selected: boolean;
value: any;
}
export interface ConflictingVersionModel {
[key: string]: Field;
selected: boolean;
}
I get this error: TS2411: Property 'selected' of type 'boolean' is not assignable to 'string' index type 'Field'.
the same one if I try:
export interface ConflictingVersionModel {
[key: string]: {
selected: boolean;
value: any;
};
selected: boolean;
}
Any ideas on what might be wrong?
Yeah that won't work. An index signature means 'all properties of this object have this type'.
You can however achieve what it looks like you are trying to do using an intersection type
export interface Field {
selected: boolean;
value: any;
}
type ConflictingVersionModel = {
[key: string]: Field;
} & { selected: boolean }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With