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

Refactor use of unnecessary generics #930

Closed
mojo2012 opened this issue Oct 19, 2020 · 1 comment
Closed

Refactor use of unnecessary generics #930

mojo2012 opened this issue Oct 19, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@mojo2012
Copy link

Hi,

method signatures like this make the autocomplete suggestions in VSCode really hard to read:

findAll<P extends Populate<T> = any>(options?: FindOptions<T, P>): Promise<Loaded<T, P>[]>;

I think it is even discouraged to use generic parameters in case the param type is only used once, like the P in your case.

I suggest to change it to something this:

findAll(options?: FindOptions<T, Populate<T>>): Promise<Loaded<T, Populate<T>>[]>;

Mind, I'm not a typescript expert

The less I have to skim back and forth to understand what P, T and other types are, the better!

@mojo2012 mojo2012 added the enhancement New feature or request label Oct 19, 2020
@B4nan
Copy link
Member

B4nan commented Oct 19, 2020

It's not "unnecessary usage", your suggestion would not work the same.

The P is a populate hint, that will be inferred based on the find options, without using it, the Loaded type would not get the inferred "type value" based on the parameters, but a generic Populate<T>.

If you do em.find(Author, ['books']), the return type will be Loaded<Author, 'books'>[] - and that will allow you to access type safe getters on the populated properties (here the books collection).

For more context see the PR that introduced Loaded type hint: #691

@B4nan B4nan closed this as completed Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants