-
Notifications
You must be signed in to change notification settings - Fork 190
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
base: main
Are you sure you want to change the base?
Conversation
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
Requesting a review from @sorvell who wrote the current section. |
There was a problem hiding this 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`. |
There was a problem hiding this comment.
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.
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 causeuseDefineForClassFields
to default totrue
, not justesnext
. See microsoft/TypeScript#45653