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

fix: Resolve promise types for props passed to store.createRecord() #9396

Merged

Conversation

seanCodes
Copy link
Contributor

@seanCodes seanCodes commented May 10, 2024

Description

Fix incorrect types being expected by the store service’s createRecord() method. This could happen when the record being created had, for example, a belongsTo relationship, in which case the type for the property with the relationship was PromiseBelongsTo<SomeModel> rather than SomeModel.

Cause

When determining the TS type for properties that can be passed to createRecord() a CreateRecordProperties utility type is used. It in turn uses a FilteredKeys type to narrow the properties to only the model attributes. Promise types were not being handled here and only filtered, leading to the issue.

Fix

To resolve any promise types like PromiseBelongsTo, a new AwaitedKeys<Type> utiltity type was added that wraps FilteredKeys. It’s a mapped type that applies Awaited to all keys, resolving promise types.

Notes for the release

N/A

@runspired runspired added 🎯 canary PR is targeting canary (default) 🏷️ feat This PR introduces a new feature typescript For issues and PRs relating to typescript convertion labels May 10, 2024
Copy link
Contributor

@runspired runspired left a comment

Choose a reason for hiding this comment

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

needs a lint fix but otherwise 👍🏻

@runspired runspired merged commit a175b6d into emberjs:main May 11, 2024
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎯 canary PR is targeting canary (default) 🏷️ feat This PR introduces a new feature typescript For issues and PRs relating to typescript convertion
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants