I have this:
JavaScript
x
12
12
1
export class DESSet<V> extends Set<V extends {id: string}> {
2
3
toJSON() {
4
5
return {
6
size: this.size,
7
values: Array.from(this.values()).map(v => v.id)
8
}
9
10
}
11
}
12
this syntax doesn’t seem to work. I also tried:
JavaScript
1
2
1
Set<V implements {id: string}>
2
but that’s no bueno either, do I really need to use a class or interface, is there not a way to do it inline?
Advertisement
Answer
Whoops that was dumb, just put the extends
on the wrong generic parameter,
this is fine:
JavaScript
1
4
1
export class DESSet<V extends {id:string}> extends Set<V> {
2
// ...
3
}
4
and so is this:
JavaScript
1
9
1
export interface HasId {
2
id: string
3
}
4
5
6
export class DESSet<V extends HasId> extends Set<V> {
7
// ...
8
}
9