Skip to content

Update documentation for TypeScript Model Definition & Class Fields - #13861

Closed
ephys wants to merge 5 commits into
sequelize:v6from
ephys:feature/docs-class-fields-caveat-v6
Closed

ephys wants to merge 5 commits into
sequelize:v6from
ephys:feature/docs-class-fields-caveat-v6

Conversation

@ephys

@ephys ephys commented Dec 29, 2021 •

Copy link
Copy Markdown
Member

Pull Request Checklist

  • [n/a] Have you added new tests to prevent regressions?
  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • [n/a] Did you update the typescript typings accordingly (if applicable)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description Of Change

There is an incompatibility between Sequelize & adding public class fields for attributes.

This PR documents how this incompatibility & explains how to add typing without introducing actual class fields that will cause bugs.

It also detects uses of public class fields that shadow a model's attributes, and warns the user. Doing this:

image

Will log the following to the console:

image

Closes #10579
Closes #12603
Closes #11675
Closes #11032
Closes #11494


Note: this documentation update is a temporary fix as things are going to break again once decorators are stage 4. I'll open an rfc with possible solutions that resolve this caveat for good for V7.

@ephys ephys self-assigned this Dec 30, 2021
@ephys ephys mentioned this pull request Dec 30, 2021
2 of 7 tasks
sdepold
sdepold previously approved these changes Dec 30, 2021
In TypeScript, you can add typing information without adding an actual public class field by using the `declare` keyword:

```typescript
// Invalid

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is it invalid or valid? :D

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch! Changed, it is valid :)

@sdepold

sdepold commented Dec 30, 2021

Copy link
Copy Markdown
Member

do we want to have that in v7 as well and eventually remove it?

@ephys

ephys commented Dec 30, 2021

Copy link
Copy Markdown
Member Author

Yes let's add it to v7 too until we've resolved #14300 :)

@sdepold sdepold closed this Jan 1, 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.

2 participants