我正在尝试为我当前的项目构建一些基类。 Currenty我收到这个编译器错误:
类型'IConcreteScope'不满足类型参数'TScope extends IEntityScope'的约束'IEntityScope'。
当我尝试运行此代码时:
// 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> {
}
此处是TypeScript playground code
的链接我做错了什么?
答案 0 :(得分:1)
代码很好;这是编译器中的一个错误。这在开发分支的最新资源中编译时没有错误。