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

New<T> strip nullability information from entity properties #2727

Closed
BennoDev opened this issue Feb 8, 2022 · 2 comments
Closed

New<T> strip nullability information from entity properties #2727

BennoDev opened this issue Feb 8, 2022 · 2 comments

Comments

@BennoDev
Copy link

BennoDev commented Feb 8, 2022

Describe the bug

The New type that gets returned from .create() methods does some funky things. It seems to strip nullability from properties.

Stack trace

No stack trace, as it's a type issue.

To Reproduce

Reproducing this is very simple using just a class and the New type.

class MyEntity {
 @Property({ nullable: true })
 nullableProperty: null | string;
}

// Type `null` is not assignable to `string`
const myNewEntityInstance: New<MyEntity> = {
 nullableProperty: null,
};

I know we would never instantiate a New<MyEntity> like above, but whether we do it via a create call or manually makes no difference for the type information.

Expected behavior

It should not modify the entity's type information. The actual type result from a .create() call is now potentially incorrect.
In the above example null is an allowed value for the MyEntity class.

Versions

Dependency Version
node 16.13.1
typescript 4.5.5
mikro-orm 5.0.0
your-driver postgresql
@B4nan
Copy link
Member

B4nan commented Feb 8, 2022

Maybe we should drop the New type (we can keep it for BC and just return T from em.create()).

@BennoDev
Copy link
Author

BennoDev commented Feb 9, 2022

That would indeed fix this, and would mean that upgrading to v5 is easier, no changes should be necessary then for .create() methods

@B4nan B4nan closed this as completed in 8ff277d Feb 9, 2022
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