Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@bengreenier
Copy link

Hi folks - I wanted to be able to omit the Entity type parameter on EntityManager.create, since I believe it can be inferred without issue. This PR attempts to allow just that.

Previously:

const user = new User();
user.id = '1';
user.name = 'Test User';
user.status = 'active';

const ret = await manager.create(user);
// ^? const ret: unknown

Now:

const user = new User();
user.id = '1';
user.name = 'Test User';
user.status = 'active';

const ret = await manager.create(user);
// ^? const ret: User

Please let me know what you think, and thanks for your hard work!

await expect(
manager.create<User>(userProperties as EntityInstance)
).rejects.toBeInstanceOf(Error);
await expect(manager.create<User>(userProperties)).rejects.toBeInstanceOf(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since there is now a relationship between the type parameter Entity and the first parameter, we actually can't keep this test exactly as is.

The options I see are:

  • drop the User type parameter altogether
  • drop the EntityInstance cast
  • use EntityInstance as the type parameter and keep the EntityInstance cast on the input
  • drop all the type parameters and rely on inference (which will be inferred as the POJO type)

I choose to drop the cast, as that felt the cleanest to me, in expressing the failure intent (you can't pass POJO objects in when an Entity instance is expected).

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

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.