Skip to content

Commit 2bc9115

Browse files
wjhsfnolanlawson
andauthored
feat(types): update types for v7 (#4186)
Co-authored-by: Nolan Lawson <nlawson@salesforce.com>
1 parent c0423f5 commit 2bc9115

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1112
-481
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
},
177177
{
178178
// Not covered by any tsconfig, so typed rules won't work, but we don't need them anyway
179-
"files": ["jest.config.js"],
179+
"files": ["jest.config.js", "**/rollup.config.js"],
180180
"extends": ["plugin:@typescript-eslint/disable-type-checked"]
181181
},
182182
{

.github/workflows/unit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ jobs:
6262
run: yarn lint
6363
- name: Check the size of the LWC bundle
6464
run: yarn bundlesize
65+
- name: Check types
66+
run: yarn test:types
6567
- name: Run Jest tests
6668
run: yarn test:ci
6769
- name: Upload Jest coverage report

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
-local-*
33
.DS_Store
44
dist/
5-
types/
65
node_modules/
76
coverage/
87
.idea/

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"test:performance": "nx test @lwc/perf-benchmarks",
2727
"test:performance:best": "nx test:best @lwc/perf-benchmarks",
2828
"test:performance:best:ci": "nx test:best:ci @lwc/perf-benchmarks",
29+
"test:types": "nx test @lwc/integration-types",
2930
"release:version": "./scripts/release/version.js"
3031
},
3132
"//": {

packages/@lwc/engine-core/src/framework/base-lightning-element.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, salesforce.com, inc.
2+
* Copyright (c) 2024, Salesforce, Inc.
33
* All rights reserved.
44
* SPDX-License-Identifier: MIT
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -56,7 +56,7 @@ import { getVMBeingRendered, isUpdatingTemplate, Template } from './template';
5656
import { HTMLElementConstructor } from './base-bridge-element';
5757
import { updateComponentValue } from './update-component-value';
5858
import { markLockerLiveObject } from './membrane';
59-
import { TemplateStylesheetFactories } from './stylesheet';
59+
import { Stylesheets } from './stylesheet';
6060
import { instrumentInstance } from './runtime-instrumentation';
6161
import { applyShadowMigrateMode } from './shadow-migration-mode';
6262

@@ -143,7 +143,7 @@ export interface LightningElementConstructor {
143143
renderMode?: 'light' | 'shadow';
144144
formAssociated?: boolean;
145145
shadowSupportMode?: ShadowSupportMode;
146-
stylesheets: TemplateStylesheetFactories;
146+
stylesheets: Stylesheets;
147147
}
148148

149149
type HTMLElementTheGoodParts = { toString: () => string } & Pick<
@@ -192,9 +192,17 @@ type RefNodes = { [name: string]: Element };
192192

193193
const refsCache: WeakMap<RefVNodes, RefNodes> = new WeakMap();
194194

195+
/**
196+
* A `LightningElement` will always be attached to an [`HTMLElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement),
197+
* rather than the more broad `Element` used by the generic shadow root interface.
198+
*/
199+
export interface LightningElementShadowRoot extends ShadowRoot {
200+
readonly host: HTMLElement;
201+
}
202+
195203
export interface LightningElement extends HTMLElementTheGoodParts, AccessibleElementProperties {
196204
constructor: LightningElementConstructor;
197-
template: ShadowRoot | null;
205+
template: LightningElementShadowRoot | null;
198206
refs: RefNodes | undefined;
199207
hostElement: Element;
200208
render(): Template;
@@ -273,7 +281,7 @@ export const LightningElement: LightningElementConstructor = function (
273281
return this;
274282
};
275283

276-
function doAttachShadow(vm: VM): ShadowRoot {
284+
function doAttachShadow(vm: VM): LightningElementShadowRoot {
277285
const {
278286
elm,
279287
mode,
@@ -531,7 +539,7 @@ function warnIfInvokedDuringConstruction(vm: VM, methodOrPropName: string) {
531539
return getClassList(elm);
532540
},
533541

534-
get template(): ShadowRoot | null {
542+
get template(): LightningElementShadowRoot | null {
535543
const vm = getAssociatedVM(this);
536544

537545
if (process.env.NODE_ENV !== 'production') {

packages/@lwc/engine-core/src/framework/check-version-mismatch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { isNull, LWC_VERSION, LWC_VERSION_COMMENT_REGEX } from '@lwc/shared';
99
import { logError } from '../shared/logger';
1010

1111
import { Template } from './template';
12-
import { StylesheetFactory } from './stylesheet';
12+
import { Stylesheet } from './stylesheet';
1313
import { LightningElementConstructor } from './base-lightning-element';
1414
import { report, ReportingEventId } from './reporting';
1515

@@ -30,10 +30,10 @@ if (process.env.NODE_ENV === 'test-karma-lwc') {
3030
* @param type
3131
*/
3232
export function checkVersionMismatch(func: Template, type: 'template'): void;
33-
export function checkVersionMismatch(func: StylesheetFactory, type: 'stylesheet'): void;
33+
export function checkVersionMismatch(func: Stylesheet, type: 'stylesheet'): void;
3434
export function checkVersionMismatch(func: LightningElementConstructor, type: 'component'): void;
3535
export function checkVersionMismatch(
36-
func: Template | StylesheetFactory | LightningElementConstructor,
36+
func: Template | Stylesheet | LightningElementConstructor,
3737
type: 'template' | 'stylesheet' | 'component'
3838
) {
3939
const versionMatcher = func.toString().match(LWC_VERSION_COMMENT_REGEX);

packages/@lwc/engine-core/src/framework/decorators/api.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, salesforce.com, inc.
2+
* Copyright (c) 2024, Salesforce, Inc.
33
* All rights reserved.
44
* SPDX-License-Identifier: MIT
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -13,15 +13,16 @@ import { getAssociatedVM } from '../vm';
1313
import { isUpdatingTemplate, getVMBeingRendered } from '../template';
1414

1515
/**
16-
* The @api decorator marks public fields and public methods in
16+
* The `@api` decorator marks public fields and public methods in
1717
* LWC Components. This function implements the internals of this
1818
* decorator.
19-
* @param target
20-
* @param propertyKey
21-
* @param descriptor
2219
*/
23-
export default function api(target: any, propertyKey: string, descriptor: PropertyDescriptor): void;
24-
export default function api() {
20+
export default function api(
21+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
22+
value: unknown,
23+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
24+
context: ClassMemberDecoratorContext | string | symbol
25+
): void {
2526
if (process.env.NODE_ENV !== 'production') {
2627
assert.fail(`@api decorator can only be used as a decorator function.`);
2728
}

packages/@lwc/engine-core/src/framework/decorators/register.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,13 @@ interface RegisterDecoratorMeta {
5959
readonly fields?: string[];
6060
}
6161

62-
const enum DescriptorType {
63-
Method = 'method',
64-
Accessor = 'accessor',
65-
Field = 'field',
66-
}
67-
68-
function getClassDescriptorType(descriptor: PropertyDescriptor): DescriptorType {
62+
function getClassDescriptorType(descriptor: PropertyDescriptor): string {
6963
if (isFunction(descriptor.value)) {
70-
return DescriptorType.Method;
64+
return 'method';
7165
} else if (isFunction(descriptor.set) || isFunction(descriptor.get)) {
72-
return DescriptorType.Accessor;
66+
return 'accessor';
7367
} else {
74-
return DescriptorType.Field;
68+
return 'field';
7569
}
7670
}
7771

packages/@lwc/engine-core/src/framework/decorators/track.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, salesforce.com, inc.
2+
* Copyright (c) 2024, Salesforce, Inc.
33
* All rights reserved.
44
* SPDX-License-Identifier: MIT
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -15,19 +15,15 @@ import { updateComponentValue } from '../update-component-value';
1515
import { logError } from '../../shared/logger';
1616

1717
/**
18-
* The @track decorator function marks field values as reactive in
18+
* The `@track` decorator function marks field values as reactive in
1919
* LWC Components. This function can also be invoked directly
2020
* with any value to obtain the trackable version of the value.
21-
* @param target
22-
* @param propertyKey
23-
* @param descriptor
2421
*/
2522
export default function track(
26-
target: any,
27-
propertyKey: string,
28-
descriptor: PropertyDescriptor
29-
): any;
30-
export default function track(target: any): any {
23+
value: unknown,
24+
context: ClassMemberDecoratorContext | string | symbol
25+
): void;
26+
export default function track<T>(target: T): T {
3127
if (arguments.length === 1) {
3228
return getReactiveProxy(target);
3329
}

packages/@lwc/engine-core/src/framework/decorators/wire.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, salesforce.com, inc.
2+
* Copyright (c) 2024, Salesforce, Inc.
33
* All rights reserved.
44
* SPDX-License-Identifier: MIT
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
@@ -12,16 +12,22 @@ import { WireAdapterConstructor } from '../wiring';
1212
import { updateComponentValue } from '../update-component-value';
1313

1414
/**
15-
* The @wire decorator wires fields and methods to a wire adapter in
16-
* LWC Components. This function implements the internals of this
17-
* decorator.
18-
* @param _adapter
19-
* @param _config
15+
* Decorator factory to wire a property or method to a wire adapter data source.
16+
* @param adapter the adapter used to provision data
17+
* @param config configuration object for the adapter
18+
* @returns A decorator function
19+
* @example
20+
* export default class WireExample extends LightningElement {
21+
* \@api bookId;
22+
* \@wire(getBook, { id: '$bookId'}) book;
23+
* }
2024
*/
2125
export default function wire(
22-
_adapter: WireAdapterConstructor,
23-
_config?: Record<string, any>
24-
): PropertyDecorator | MethodDecorator {
26+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
27+
adapter: WireAdapterConstructor,
28+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
29+
config?: Record<string, any>
30+
): (value: unknown, context: ClassMemberDecoratorContext | string | symbol) => void {
2531
if (process.env.NODE_ENV !== 'production') {
2632
assert.fail('@wire(adapter, config?) may only be used as a decorator.');
2733
}

0 commit comments

Comments
 (0)