This obviously works fine in C# but not typescript, is there a way around it or will I just have to use different names?
export interface IThing<T> extends IThing {
Value: T;
}
export interface IThing {
Name?: string;
ValueStr?: string;
Type?: string;
}
I get 'All declarations of IThing must have identical type parameters'
Apologies if I'm being dense!
You need to use different names, only name matters when identifying the interface not the number of generic type parameters.
Generics are erased at compile time in Typescript, so there is no way to distinguish between different instantiations of a generic class. Although interfaces are only a compile time construct and could possibly have been differentiated by name as well as number of generic parameters, my guess is that since classes work this way it was decided to make interfaces work in the same way.
One work around would be to use a default type argument for the interface:
export interface IThing<T = any> {
Name?: string;
ValueStr?: string;
Type?: string;
Value: T;
}
var d: IThing;
var foo: IThing<number>
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