data icon indicating copy to clipboard operation
data copied to clipboard

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

Open seanCodes opened this issue 1 year ago • 0 comments

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

seanCodes avatar May 10 '24 03:05 seanCodes