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: deep partial working with active records create and merge #9151

Closed

Conversation

bellstrand
Copy link

Description of change

#8817 partially broke create & merge functions in Active Record setups.

@Entity()
export class Item extends BaseEntity {
    @PrimaryColumn()
    id: string
    @Column()
    value: number
}

const input: Pick<Item, "value"> = { value: 42 }
const item = Item.create(input)

currently fails to compile because of

No overload matches this call.
  Overload 1 of 3, '(this: (new () => Item) & typeof BaseEntity, entityLikeArray: DeepPartial<Item>[]): Item[]', gave the following error.
    Argument of type 'Pick<Item, "value">' is not assignable to parameter of type 'DeepPartial<Item>[]'.
      Type 'Pick<Item, "value">' is missing the following properties from type 'DeepPartial<Item>[]': length, pop, push, concat, and 26 more.
  Overload 2 of 3, '(this: (new () => BaseEntity) & typeof BaseEntity, entityLike: DeepPartial<BaseEntity>): BaseEntity', gave the following error.
    Argument of type 'Pick<Item, "value">' is not assignable to parameter of type 'DeepPartial<BaseEntity>'.ts(2769)
BaseEntity.ts(185, 12): The call would have succeeded against this implementation, but implementation signatures of overloads are not externally visible.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run format to apply prettier formatting
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #9150
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change - N/A
  • The new commits follow conventions explained in CONTRIBUTING.md

const input: Pick<Item, "value"> = { value: 42 }
const item = Item.create(input)

Active Record entities created with BaseEntitys, create and merge
functions now works with limited input just like before 0.3.5
@pleerock
Copy link
Member

Thanks for the contribution.

We need a better solution that solves all the issues. Now it breaks DeepPartial<Item> usage and solves Pick<Item, "value"> issue. But DeepPartial<Item> also a valid issue.

So the question is what other usages currently break? Maybe root cause is different and we should seek for a different solution?

@pleerock
Copy link
Member

I think current implementation is just a hack it doesn't really solve the issue.

Solution to the issue is to explicitly specify Item to a generic parameter T:

Item.create<Item>(input)

I don't think this issue can be resolved until microsoft/TypeScript#5863 would be.

@pleerock
Copy link
Member

pleerock commented Dec 3, 2022

Closing as there is no answer from author.

@pleerock pleerock closed this Dec 3, 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

Successfully merging this pull request may close these issues.

None yet

2 participants