Harsha
Harsha

Reputation: 897

Generic Type Inheritance in TypeScript

I am pretty new to Typescript. Please help me in explaining what is wrong with the below code snippet.

interface ICalcValue {

    readonly IsNumber : boolean;

    readonly : IsString : boolean;

}



interface ICalcValue<T> extends ICalcValue {

    readonly T Value;

}

Upvotes: 0

Views: 589

Answers (1)

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

Reputation: 250236

Unlike other languages (ex C#). Having two types that differ only by type parameters is not possible in typescript. You will need to use different names for the interfaces (fixing the other minor syntax errors):

interface ICalcValueBase {

    readonly IsNumber: boolean;

    readonly IsString: boolean;

}

interface ICalcValue<T> extends ICalcValueBase {

    readonly Value: T;

}

play

Upvotes: 1

Related Questions