jinqu-odata icon indicating copy to clipboard operation
jinqu-odata copied to clipboard

expand with selector brings a tsc error in strict mode

Open buchatsky opened this issue 2 years ago • 0 comments

jinqu-odata version

1.1.3

Steps to reproduce

tsc brings an error when all of the following conditions are satisfied:

  • tsconfig.strictNullChecks=true (or strict=true and strictNullChecks is omited);
  • the expanded navigation property is optional in referencing type;
  • the expanded navigation property type is derived from another type e.g.
export class BaseEntity {
}
export class Category extends BaseEntity {
    Id!: number;
    CategoryName!: string;
}
export class Product {
    Id!: number;
    ProductName!: string;
    CategoryId?: number;
    Category?: Category;
}
...
let query: IODataQuery<Product> = this.context.products()
    .expand('Category', ['CategoryName']);

Expected behavior

No errors

Actual behavior

tsc error TS2769 Type 'string' is not assignable to type 'never'

Workaround

In odata-query.ts (or d.ts)

//declare type AU<T> = T extends any[] ? T[0] : T;
declare type XU<T> = T extends undefined ? never : T;
declare type AU<T> = XU<T extends any[] ? T[0] : T>;

The error disappears and the tsc transpiling passes, but typescript does not control the selector's field list (probably because jinqu-odata itself is built without strictNullChecks). I tried to set "strict: true" in tsconfig for jinqu-odata but it brings too many errors, so I gave it up

buchatsky avatar Apr 14 '22 21:04 buchatsky