There are functions in third-party libraries that extend objects to add more functions to them. e.g. seamless-immutable
I want to create a definition file for such a library. I thought something in the line
interface ImmutableMethods<T> extends T{ set?<U>(key: string | number, value: any): T | U; setIn?<U>(keys: Array<string>, value: any): T | U; ... } function Immutable<T>(obj: T, options?): ImmutableMethods<T>
Then I can declare my own types as:
interface Type1 {prop1, prop2} interface Type2 {propOfType1: ImmutableMethods<Type1>} var immutableType2:Type2 = Immutable(...)
And then I will have an Immutable function for all my objects.
But the problem is that the line interface ImmutableMethods<T> extends T gives me the error "An interface can only extend a class or another interface"
Is there a way to declare that T is an interface or a completely different way to get this extended behavior?
source share