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(repository): fix DynamicModelCtor type to correctly preserve Props #5600

Merged
merged 1 commit into from
May 29, 2020

Conversation

bajtos
Copy link
Member

@bajtos bajtos commented May 29, 2020

Before this change, the following code would create an instance with the type of the base model class, ignoring custom model properties:

const Product = defineModelClass<typeof Model, {name: string}>(
  Model,
  definition,
);
const p = new Product();
// p has type Model now

This patch fixes the problem by changing the order in which constructor functions are defined in DynamicModelCtor, so that the compiler always picks the constructor returning Base & Props.

I discovered this problem while reviewing #5591.

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

Before this change, the following code would create an instance
with the type of the base model class, ignoring custom model properties:

```ts
const Product = defineModelClass<typeof Model, {name: string}>(
  Model,
  definition,
);
const p = new Product();
// p has type Model now
```

This patch fixes the problem by changing the order in which constructor
functions are defined in `DynamicModelCtor`, so that the compiler always
picks the constructor returning `Base & Props`.

Signed-off-by: Miroslav Bajtoš <[email protected]>
@bajtos bajtos added bug Repository Issues related to @loopback/repository package labels May 29, 2020
@bajtos bajtos requested a review from hacksparrow May 29, 2020 06:41
@bajtos bajtos requested a review from agnes512 as a code owner May 29, 2020 06:41
@bajtos bajtos self-assigned this May 29, 2020
@bajtos bajtos merged commit 927789e into master May 29, 2020
@bajtos bajtos deleted the fix/dynamic-model-ctor branch May 29, 2020 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Repository Issues related to @loopback/repository package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants