Skip to content

Commit 87ef880

Browse files
JeanMechepkozlowski-opensource
authored andcommitted
refactor(core): cleanup DebugElement (angular#50896)
* `style` is never `null`. * adding some typing * Add 2 todos per angular#49777 PR Close angular#50896
1 parent a0dc12b commit 87ef880

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

packages/core/src/debug/debug_node.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,10 @@ export class DebugElement extends DebugNode {
178178
/**
179179
* A map of attribute names to attribute values for an element.
180180
*/
181+
// TODO: replace null by undefined in the return type
181182
get attributes(): {[key: string]: string|null} {
182183
const attributes: {[key: string]: string|null} = {};
183-
const element = this.nativeElement;
184+
const element = this.nativeElement as Element | undefined;
184185

185186
if (!element) {
186187
return attributes;
@@ -233,16 +234,11 @@ export class DebugElement extends DebugNode {
233234

234235
/**
235236
* The inline styles of the DOM element.
236-
*
237-
* Will be `null` if there is no `style` property on the underlying DOM element.
238-
*
239-
* @see [ElementCSSInlineStyle](https://developer.mozilla.org/en-US/docs/Web/API/ElementCSSInlineStyle/style)
240237
*/
238+
// TODO: replace null by undefined in the return type
241239
get styles(): {[key: string]: string|null} {
242-
if (this.nativeElement && (this.nativeElement as HTMLElement).style) {
243-
return (this.nativeElement as HTMLElement).style as {[key: string]: any};
244-
}
245-
return {};
240+
const element = this.nativeElement as HTMLElement | null;
241+
return (element?.style ?? {}) as {[key: string]: string | null};
246242
}
247243

248244
/**

0 commit comments

Comments
 (0)