Skip to content

Commit 0945a11

Browse files
authored
Merge branch 'master' into dependabot/npm_and_yarn/vite-6.3.4
2 parents b2e4108 + be20445 commit 0945a11

File tree

5 files changed

+45
-7
lines changed

5 files changed

+45
-7
lines changed

.nucleus.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ branches:
3838
spring25:
3939
pull-request:
4040
<<: *branch-definition
41+
summer25:
42+
pull-request:
43+
<<: *branch-definition
4144
jobs:
4245
build-and-test:
4346
memory-limit: 16

packages/@lwc/engine-dom/src/apis/create-element.ts

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,28 @@ if (process.env.NODE_ENV !== 'production') {
9898
}
9999

100100
/**
101-
* Properties defined on the component class, excluding those inherited from `LightningElement`.
101+
* Gets the public properties of a component class. If the `__lwc_public_property_types__` property
102+
* is defined, it will be used as the source of truth for the property types. Otherwise, all of the
103+
* properties defined on the component class are used, excluding those inherited from `LightningElement`.
104+
*
105+
* IMPORTANT: If the fallback is used, then _all_ component properties are returned, rather than
106+
* just the public properties.
102107
*/
103-
// TODO [#4292]: Restrict this to only @api props
104-
type ComponentClassProperties<T> = Omit<T, keyof LightningElement>;
108+
type ComponentClassProperties<T> = T extends {
109+
readonly __lwc_public_property_types__?: infer Props extends object;
110+
}
111+
? Props
112+
: Omit<T, keyof LightningElement>;
105113

106114
/**
107115
* The custom element returned when calling {@linkcode createElement} with the given component
108116
* constructor.
109117
*
110-
* NOTE: The returned type incorrectly includes _all_ properties defined on the component class,
118+
* NOTE: By default, the returned type includes _all_ properties defined on the component class,
111119
* even though the runtime object only uses those decorated with `@api`. This is due to a
112-
* limitation of TypeScript. To avoid inferring incorrect properties, provide an explicit generic
113-
* parameter, e.g. `createElement<typeof LightningElement>('x-foo', { is: FooCtor })`.
120+
* limitation of TypeScript. For example:
114121
*
115-
* @example ```
122+
* ```
116123
* class Example extends LightningElement {
117124
* @api exposed = 'hello'
118125
* internal = 'secret'
@@ -124,6 +131,29 @@ type ComponentClassProperties<T> = Omit<T, keyof LightningElement>;
124131
* const internal = example.internal // type is 'string'
125132
* console.log(internal) // prints `undefined`
126133
* ```
134+
*
135+
* One way to avoid inferring incorrect properties, is to provide an explicit generic parameter.
136+
* For example:
137+
* ```
138+
* const example = createElement<{exposed: string}>('c-example', { is: Example })
139+
* const exposed = example.exposed // type is 'string'
140+
* const internal = example.internal // Now a type error! ✅
141+
* ```
142+
*
143+
* Alternatively, you can define a type for property on the component, `__lwc_public_property_types__`,
144+
* that explicitly lists only the public properties, and the types will be inferred from that prop.
145+
* The property should be optional, because it does not actually exist at runtime.
146+
* For example:
147+
* ```
148+
* class Example extends LightningElement {
149+
* @api exposed = 'hello'
150+
* internal = 'secret'
151+
* __lwc_public_property_types__?: { exposed: string }
152+
* }
153+
* const example = createElement('c-example', { is: Example })
154+
* const exposed = example.exposed // type is 'string'
155+
* const internal = example.internal // Now a type error! ✅
156+
* ```
127157
*/
128158
export type LightningHTMLElement<T> = HTMLElement & ComponentClassProperties<T>;
129159

packages/@lwc/shared/src/aria.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export const ID_REFERENCING_ATTRIBUTES_SET: Set<string> = /*@__PURE__*/ new Set(
129129
'aria-labelledby',
130130
'aria-owns',
131131
'for',
132+
'popovertarget',
132133
]);
133134

134135
export { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap };

packages/@lwc/shared/src/html-attributes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const GLOBAL_ATTRIBUTE = /*@__PURE__*/ new Set([
8080
'lang',
8181
'nonce',
8282
'part',
83+
'popover',
8384
'slot',
8485
'spellcheck',
8586
'style',

packages/@lwc/template-compiler/src/parser/utils/html-element-attributes.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const HTML_ELEMENT_ATTRIBUTE_MAP = {
5454
'itemtype',
5555
'lang',
5656
'nonce',
57+
'popover',
5758
'slot',
5859
'spellcheck',
5960
'style',
@@ -118,6 +119,8 @@ const HTML_ELEMENT_ATTRIBUTE_MAP = {
118119
'formnovalidate',
119120
'formtarget',
120121
'name',
122+
'popovertarget',
123+
'popovertargetaction',
121124
'type',
122125
'value',
123126
],

0 commit comments

Comments
 (0)