1

I am trying to build some base classes for my current project. Currenty I am getting this compiler error:

Type 'IConcreteScope' does not satisfy the constraint 'IEntityScope' for type parameter 'TScope extends IEntityScope'.

When I try to run this code:

// scope 
export interface IScope {
    context: any;
}
export class ContextBase<TScope extends IScope> {
    scope: TScope;
} 
// entity
export interface IEntity {
    id: string;
}
export interface IEntityScope<TEntity extends IEntity> extends IScope {
    entity: TEntity;    
}
export class EntityContextBase<TEntity extends IEntity, TScope extends IEntityScope<TEntity>> {
    operation(entity: TEntity) {...}    
}
// concrete 
export interface IConcreteEntity extends IEntity {
    name: string;
}
export interface IConcreteScope extends IEntityScope<IConcreteEntity> {
    someprop: boolean;
}
// this is the problem: EntityContextBase<IConcreteEntity,IConcreteScope>
export class ConcretContext extends EntityContextBase<IConcreteEntity,IConcreteScope> {

} 

Here the link to the TypeScript playground code

What am I doing wrong?

1
  • I think the code is actually right, and the compiler is getting confused somewhere in EntityContextBase. Like it loses track of the two TEntitys being the same thing. That is not an easy structure to comprehend. Commented Oct 3, 2013 at 16:33

1 Answer 1

1

The code is fine; it's a bug in the compiler. This compiles without error in the latest sources from the develop branch.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.