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

Add TypeSafety to Entity.toObject() #4198

Closed
SpencerKaiser opened this issue Apr 6, 2023 · 2 comments
Closed

Add TypeSafety to Entity.toObject() #4198

SpencerKaiser opened this issue Apr 6, 2023 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@SpencerKaiser
Copy link
Contributor

Is your feature request related to a problem? Please describe.
.toObject does not have solid TypeSafety for the args or on the return type

Describe the solution you'd like
Refactor the method to have a signature similar to the following:

T.toObject(ignoreFields: [keyof T][]) => Omit<EntityDTO<T>, typeof ignoreFields>

I believe it's possible to infer the type of ignoreFields, but maybe not... if not, maybe a generic argument?

@SpencerKaiser SpencerKaiser added the enhancement New feature or request label Apr 6, 2023
@B4nan B4nan added this to the 6.0 milestone Apr 7, 2023
@B4nan
Copy link
Member

B4nan commented Apr 7, 2023

Looks like this does the job just fine, given we don't support dot paths in there, it can be really simple:

toObject<K extends EntityKey<T>>(ignoreFields?: K[]): Omit<EntityDTO<T>, K>;

The EntityKey type removes function properties and symbols from keys.

@B4nan
Copy link
Member

B4nan commented Apr 7, 2023

implemented via 18570d7

@B4nan B4nan closed this as completed Apr 7, 2023
jsprw pushed a commit to jsprw/mikro-orm-full-text-operators that referenced this issue May 7, 2023
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