Skip to content

Commit

Permalink
refactor: Add declare to class fields in child class that overrides…
Browse files Browse the repository at this point in the history
… a base class field without explicitly reinitializing the field.

PiperOrigin-RevId: 679013309
  • Loading branch information
material-web-copybara authored and copybara-github committed Sep 26, 2024
1 parent f5b61a9 commit 271ca16
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/mdc-switch/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ import {CssClasses} from './constants';
* State observers and event handler entrypoints update a component's adapter's
* state with the logic needed for switch to function.
*/
export class MDCSwitchFoundation extends
MDCObserverFoundation<MDCSwitchAdapter> {
export class MDCSwitchFoundation extends MDCObserverFoundation<MDCSwitchAdapter> {
constructor(adapter: MDCSwitchAdapter) {
super(adapter);
this.handleClick = this.handleClick.bind(this);
Expand Down Expand Up @@ -79,7 +78,7 @@ export class MDCSwitchFoundation extends
* render adapter to keep the component's DOM updated with the state.
*/
export class MDCSwitchRenderFoundation extends MDCSwitchFoundation {
protected override adapter!: MDCSwitchRenderAdapter;
protected declare adapter: MDCSwitchRenderAdapter;

/**
* Initializes the foundation and starts observing state changes.
Expand All @@ -90,7 +89,7 @@ export class MDCSwitchRenderFoundation extends MDCSwitchFoundation {
disabled: this.onDisabledChange,
processing: this.onProcessingChange,
selected: this.onSelectedChange,
})
});
}

/**
Expand All @@ -107,8 +106,9 @@ export class MDCSwitchRenderFoundation extends MDCSwitchFoundation {
// Ensure aria-checked is set if attribute is not present
this.onSelectedChange();
this.adapter.state.disabled = this.adapter.isDisabled();
this.adapter.state.processing =
this.adapter.hasClass(CssClasses.PROCESSING);
this.adapter.state.processing = this.adapter.hasClass(
CssClasses.PROCESSING,
);

// Re-observe state
this.setObserversEnabled(this.adapter.state, true);
Expand Down

0 comments on commit 271ca16

Please sign in to comment.