TS2428 error TS2428: All declarations of ‘Strategy
‘ must have identical type parameters.
Broken Code ❌ Strategy.ts 1 2 3 4 5 6 7 8 9 10 11 enum TOPIC { ON_LOGOUT = 'ON_LOGOUT' , }export interface Strategy { on (event : TOPIC .ON_LOGOUT , listener : (reason: string ) => void ): this ; }export abstract class Strategy <SpecificConfig extends StrategyConfig > extends EventEmitter { }
Fixed Code ✔️ Solution: The generic abstract class Strategy
has a generic type parameter list in angle brackets (diamond notation). This generic type parameter list must also be added to the interface definition of Strategy
.
Strategy.ts 1 2 3 4 5 6 7 8 9 10 11 enum TOPIC { ON_LOGOUT = 'ON_LOGOUT' , }export interface Strategy <SpecificConfig extends StrategyConfig > { on (event : TOPIC .ON_LOGOUT , listener : (reason: string ) => void ): this ; }export abstract class Strategy <SpecificConfig extends StrategyConfig > extends EventEmitter { }