I have a problem which produces these errors on the console.
Type 'WebFieldB' does not satisfy the constraint 'WebFieldA & WebFieldB'.
There are 2 classes generated by server, which shouldn't be changed.
class WebFieldA {
readonly Name: string;
readonly IsUpdatable: boolean;
}
class WebFieldB {
readonly Name: string;
}
And this is my code:
interface IFieldInfo {
name: string;
isUpdatable: boolean;
}
class SomeField<T extends WebFieldA & WebFieldB> implements IFieldInfo {
field: T;
constructor(pField: T) {
this.field = pField;
}
get name(): string {
return this.field.Name;
};
get isUpdatable(): boolean {
return this.field.IsUpdatable || false;
}
}
let field1: IFieldInfo = new SomeField<WebFieldA>({Name: 'fieldA', IsUpdatable: false});
let field2: IFieldInfo = new SomeField<WebFieldB>({Name: 'fieldB'}); **// Here for WebFieldB is error**
let myCollection: Array<IFieldInfo> = [field1, field2];
What do I expect?
I would like to have a collection of IFieldInfo built from objects of 2 types: WebFieldA and WebFieldB (WFB has no isUpdatable property!). Unfortunately i can modify only my code, not WebFieldA or WebFieldB.
And maybe another idea, to make this without generics? I don't know...