Closed
Description
Apologies I this is a dup.
The situation comes up often. I define an interfaces for my API JSON responses and I wish they were classes so I could define instance methods on them. Say for mutation, or just helpful convenience methods.
Sure I can use standalone functions that take the interface as the first parameter but discover-ability sucks.
Something like this:
interface Rect {
x: number;
y: number;
width: number;
height: number;
}
function area(rect: this Rect): number {
return rect.widht * rect.height;
}