KingKerosin
KingKerosin

Reputation: 3841

TypeScript - ReSharper shows error for generic inheritance but project builds fine

After upgrading to ReSharper 10 the following error is shown but it builds without any error.

Class 'BaseTourModule' cannot extend class 'BaseModule': Types of property 'settings' of types 'BaseModule' and 'BaseTourModule' are incompatible Type parameter 'TSetup' constraint isn't related to 'TSetup' Type parameter 'TSetup' is incompatible with 'BaseTourModuleSetup', which is not type parameter

Whereas BaseModule is defined as

export abstract class BaseModule<TSetup extends BaseModuleSetup> {
    protected settings: TSetup;
}

and BaseModuleSetup

export abstract class BaseModuleSetup {
    protected translations: { [index: string]: string; } = {};
    abstract isValid(): boolean;
}

The concrete implementation of BaseTourModule (where the error is thrown) is:

export abstract class BaseTourModule<TSetup extends BaseTourModuleSetup> extends BaseModule<TSetup> {

}

Last, but not least, this is the implementation of BaseTourModuleSetup

export abstract class BaseTourModuleSetup extends BaseModuleSetup {
}

I'm using Visual Studio 2015 Professsional and the project is building against ECMAScript 5 using TypeScript 1.6. Is this an error by ReSharper or is there something wrong which I don't see?

Upvotes: 1

Views: 422

Answers (2)

Anton
Anton

Reputation: 827

That's a bug in ReSharper 10.0. Is already fixed for bugfix update 10.0.1, which will be released relatively soon.

Upvotes: 4

gilamran
gilamran

Reputation: 7304

Looks like you used casting in your inheritance, and from what I understood, it should look like this:

export abstract class BaseModuleSetup {
    protected translations: { [index: string]: string; } = {};
    abstract isValid(): boolean;
}

export abstract class BaseModule extends BaseModuleSetup {
    protected settings: TSetup;
}

export abstract class BaseTourModuleSetup extends BaseModuleSetup {
}

export abstract class BaseTourModule extends BaseTourModuleSetup {
}

Anyways, (Without really knowing what your are trying to achieve) it looks like your are over complicating this with class hierarchy.

If you want, you can explain what are your goals and we can build the best class diagram for your needs.

Upvotes: 0

Related Questions