observe reporting incorrect type under observation
I'm using FJP 3.0.0-1 on TypeScript 3.9 with Angular 9
I've got a strongly types set of UDTs analogous to:
export class ChildClass { Id: number}
export class ParentClass {
myList: Array<ChildClass>;
constructor() {
this.myList = new Array<ChildClass>();
}
}
export class MyComponent implements OnInit, OnDestroy{
obj: ParentClass;
observer: Observer<Array<ChildClass>>;
ngOnInit(): void {
this.obj = new ParentClass();
this.observer = jsonpatch.observe(this.obj.myList); // *1
}
ngOnDestroy(): void {
if (this.observer) {
jsonpatch.unobserve(this.obj.myList, this.observer); // *2
}
}
Note 1: in the current setup, this line throws a compile time exception: Type 'Observer<ChildClass>' is not assignable to type 'Observer<ChildClass[]>'
Note 2: if I change observer to Observer<ChildClass>, then this line throws a compile time exception.
I can work around the compile time exceptions by using Observer<any> or Observer<ChildClass | Array<ChildClass>>, but that does defeat the purpose of strongly typed code.
cc @Starcounter-Jack
I suspect this is not a complete runnable example (for example there is an uncompilable comma at jsonpatch,observe(this.obj.myList); // *1.
It also appears that the type signature of this.obj.mylist is a UserGroup or an array of the same.
@Starcounter-Jack
I suspect this is not a complete runnable example (for example there is an uncompilable comma at
jsonpatch,observe(this.obj.myList); // *1.It also appears that the type signature of
this.obj.mylistis aUserGroupor an array of the same.
Fixed your issue with the typo in the example - sorry, I tried to quickly write a simple example rather than paste my actual code base, which I cant for obvious reasons. Do you want a stack blitz or something?
Updated the workaround paragraph to match the example classes.