-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(decorators): update decorator types @W-16373548@ (#4429)
* chore: hushsky * feat(wire): ensure prop type matches adapter value * fix(wire): account for reactive prop replacement * feat(wire): drop experimental decorator signature * refactor(api): only support modern decorators also, only allow @api on LightningElement classes * refactor(track): only support modern decorators also, only allow on LightningElements * refactor(wire): only support modern decorators also, only allow on LightningElements * refactor(integration-types): remove tests for experimental decorators * docs: add comment explaining assertions * refactor(playground): remove experimental decorator support * refactor(integration-types): split decorator tests into multiple files one file per decorator * refactor(track): make function signature work as decorator and non-decorator * refactor(wire): allow values to be undefined * test(wire): expand type validations * docs: simplify comment * test(wire): expand type validations * feat(wire): properly type reactive values * test(wire): expand type validations * test(decorators): validate type error when used on non-components * refactor(wire): method param is never explicit undefined * test(wire): split type validations into separate classes * refactor(wire): @wire cannot be used on getters/setters * test(wire): validate that nested props are not reactive * fix(test): use correct context type * docs: clarify comment * revert(track): check arguments instead of undefined * test(wire): validate wire doesn't work on non-component with superclass * fix(wire): make wire work with adapters typed as `any` * test(types): assert decorators don't work on non-LightningElement classes * refactor(wire): remove type error if extending a non-component TypeScript can't differentiate between a class without a superclass and a class that extends `any`. Because extending `any` is probably a fairly common use case (e.g. base components without a type stub), we need to allow it, at the cost of also allowing non-extended classes. * feat(wire): update signature to allow decorating getters/setters * docs(wire): add comments to decorator type * refactor(wire): update type def to always split on "." runtime behavior is to use "." as a delimiter, never as part of the property key * test(wire): update type validations for prop/method decorators * test(wire): add type validations for decorated getters * test(wire): add type validations for decorated setters * feat(wire): allow undefined in wired getter * refactor(decorators): relax type constraint restricting to LightningElement Components could extend a superclass typed as `any` * chore(decorators): remove useless generic type param * docs(test): clarify use of nested.prop * chore: prettier
- Loading branch information
Showing
12 changed files
with
559 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2024, Salesforce, Inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
import { LightningElement, api } from 'lwc'; | ||
|
||
// @ts-expect-error bare decorator cannot be used | ||
api(); | ||
|
||
// @ts-expect-error decorator doesn't work on classes | ||
@api | ||
export default class Test extends LightningElement { | ||
@api optionalProperty?: string; | ||
@api propertyWithDefault = true; | ||
@api nonNullAssertedProperty!: object; | ||
@api method() {} | ||
@api getter(): undefined {} | ||
@api setter(_: string) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2024, Salesforce, Inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
import { LightningElement, track } from 'lwc'; | ||
|
||
// This is okay! track has a non-decorator signature | ||
track(123); | ||
// This is okay because we treat implicit and explicit `undefined` identically | ||
track(123, undefined); | ||
// @ts-expect-error wrong number of arguments | ||
track(); | ||
// @ts-expect-error wrong number of arguments | ||
track({}, {}); | ||
|
||
// @ts-expect-error doesn't work on classes | ||
@track | ||
export default class Test extends LightningElement { | ||
@track optionalProperty?: string; | ||
@track propertyWithDefault = true; | ||
@track nonNullAssertedProperty!: object; | ||
// @ts-expect-error cannot be used on methods | ||
@track method() {} | ||
// @ts-expect-error cannot be used on getters | ||
@track getter(): undefined {} | ||
// @ts-expect-error cannot be used on setters | ||
@track setter(_: string) {} | ||
} |
Oops, something went wrong.