Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong typing #46

Open
its-dibo opened this issue Apr 19, 2024 · 2 comments
Open

wrong typing #46

its-dibo opened this issue Apr 19, 2024 · 2 comments

Comments

@its-dibo
Copy link

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
Copy link
Member

zaro commented Apr 23, 2024

@its-dibo Which TS version are you using?

@its-dibo
Copy link
Author

Which TS version are you using?

5.4.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants