gid-oss / dataui-nestjs-crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
114 stars 29 forks source link

wrong typing #46

Open its-dibo opened 2 months ago

its-dibo commented 2 months ago

in docs there is an example to override a method like this

  get base(): CrudController<Hero> {
    return this;
  }

  @Override()
  getMany(
    @ParsedRequest() req: CrudRequest,
  ) {
    return this.base.getManyBase(req);
  }

however, the base methods such as getManyBase is typed to return a promise or undefined so, the previous snippet makes TS to give this error

Cannot invoke an object which is possibly 'undefined'.ts(2722)

we can make an ugly workaround and edit our code to be

 return this.base.getManyBase?.(req);

this also makes TS complain again because the overrides method i.e. getMany() should return Promise only, not promise or undefined

zaro commented 2 months ago

@its-dibo Which TS version are you using?

its-dibo commented 2 months ago

Which TS version are you using?

5.4.5