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

Include use of TS declare syntax #583

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

KeithHenry
Copy link

@KeithHenry KeithHenry commented Nov 2, 2021

TS can use class fields with decorators without turning off useDefineForClassFields at the cost of losing inline initialisation.

See #479 and lit/lit#1985 for discussion.

Also clarified version, as es2020 or above will cause useDefineForClassFields to default to true, not just esnext. See microsoft/TypeScript#45653

TS can use class fields with decorators without turning off useDefineForClassFields at the cost of losing inline initialisation
see lit#479 and lit/lit#1985 for discussion
es2020 will cause useDefineForClassFields to default to true
@arthurevans
Copy link
Contributor

Requesting a review from @sorvell who wrote the current section.

@aomarks aomarks added cla: yes and removed cla: yes labels Jan 12, 2022
Copy link
Contributor

@justinfagnani justinfagnani left a comment

Choose a reason for hiding this comment

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

@KeithHenry sorry this review took so long! The declare info was already added, but the es2020 bit wasn't, if you care to resubmit.

@@ -130,6 +130,8 @@ constructor() {

For **TypeScript**, you **may use class fields** for declaring reactive properties as long as the `useDefineForClassFields` setting in your `tsconfig` is set to `false`. Note, this is not required for some configurations of TypeScript, but it's recommended to explicitly set it to `false`.

For **TypeScript**, you can use `declare` syntax for class fields that you explicitly want to exclude from the JS output regardless of the `useDefineForClassFields` setting. This will allow you to use decorators, but cannot be initialised inline. Similar to JS declared fields can only be initialised in the `constructor`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this info was added at some point. It would be nice to get a link to https://www.typescriptlang.org/docs/handbook/2/classes.html#type-only-field-declarations in there though.

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

4 participants