Skip to content

docs: add types to public methods and getters/setters #9558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/cdk-experimental/dialog/dialog-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,21 @@ export class CdkDialogContainer extends BasePortalOutlet {
// metadata is not inherited by child classes, instead the host binding data is defined in a way
// that can be inherited.
// tslint:disable:no-host-decorator-in-concrete
@HostBinding('attr.aria-label') get _ariaLabel() { return this._config.ariaLabel || null; }
@HostBinding('attr.aria-label')
get _ariaLabel(): string | null { return this._config.ariaLabel || null; }

@HostBinding('attr.aria-describedby')
get _ariaDescribedBy() { return this._config ? this._config.ariaDescribedBy : null; }
get _ariaDescribedBy(): string | null | undefined {
return this._config ? this._config.ariaDescribedBy : null;
}

@HostBinding('attr.role') get _role() { return this._config ? this._config.role : null; }
@HostBinding('attr.role')
get _role(): string | null | undefined {
return this._config ? this._config.role : null;
}

@HostBinding('attr.tabindex') get _tabindex() { return -1; }
@HostBinding('attr.tabindex')
get _tabindex(): number { return -1; }
// tslint:disable:no-host-decorator-in-concrete

/** The portal host inside of this container into which the dialog content will be loaded. */
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/a11y/focus-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export class FocusMonitor implements OnDestroy {
})
export class CdkMonitorFocus implements OnDestroy {
private _monitorSubscription: Subscription;
@Output() cdkFocusChange = new EventEmitter<FocusOrigin>();
@Output() cdkFocusChange: EventEmitter<FocusOrigin> = new EventEmitter<FocusOrigin>();

constructor(private _elementRef: ElementRef, private _focusMonitor: FocusMonitor) {
this._monitorSubscription = this._focusMonitor.monitor(
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/a11y/focus-trap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class FocusTrap {
}

/** Destroys the focus trap by cleaning up the anchors. */
destroy() {
destroy(): void {
if (this._startAnchor && this._startAnchor.parentNode) {
this._startAnchor.parentNode.removeChild(this._startAnchor);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/a11y/list-key-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
tabOut: Subject<void> = new Subject<void>();

/** Stream that emits whenever the active item of the list manager changes. */
change = new Subject<number>();
change: Subject<number> = new Subject<number>();

/**
* Turns on wrapping mode, which ensures that the active item will wrap to
Expand Down
14 changes: 7 additions & 7 deletions src/cdk/accordion/accordion-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ export class CdkAccordionItem implements OnDestroy {

/** Whether the AccordionItem is expanded. */
@Input()
get expanded(): any { return this._expanded; }
set expanded(expanded: any) {
expanded = coerceBooleanProperty(expanded);
get expanded(): boolean { return this._expanded; }
set expanded(value: boolean) {
value = coerceBooleanProperty(value);

// Only emit events and update the internal value if the value changes.
if (this._expanded !== expanded) {
this._expanded = expanded;
this.expandedChange.emit(expanded);
if (this._expanded !== value) {
this._expanded = value;
this.expandedChange.emit(value);

if (expanded) {
if (value) {
this.opened.emit();
/**
* In the unique selection dispatcher, the id parameter is the id of the CdkAccordionItem,
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/accordion/accordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let nextId = 0;
})
export class CdkAccordion {
/** A readonly id value to use for unique selection coordination. */
readonly id = `cdk-accordion-${nextId++}`;
readonly id: string = `cdk-accordion-${nextId++}`;

/** Whether the accordion should allow multiple expanded accordion items simulateously. */
@Input()
Expand Down
5 changes: 2 additions & 3 deletions src/cdk/bidi/dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ import {Direction, Directionality} from './directionality';
exportAs: 'dir',
})
export class Dir implements Directionality, AfterContentInit, OnDestroy {
_dir: Direction = 'ltr';

/** Whether the `value` has been set to its initial value. */
private _isInitialized: boolean = false;

/** Event emitted when the direction changes. */
@Output('dirChange') change = new EventEmitter<Direction>();
@Output('dirChange') change: EventEmitter<Direction> = new EventEmitter<Direction>();

/** @docs-private */
@Input()
Expand All @@ -48,6 +46,7 @@ export class Dir implements Directionality, AfterContentInit, OnDestroy {
this.change.emit(this._dir);
}
}
_dir: Direction = 'ltr';

/** Current layout direction of the element. */
get value(): Direction { return this.dir; }
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/bidi/directionality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class Directionality {
readonly value: Direction = 'ltr';

/** Stream that emits whenever the 'ltr' / 'rtl' state changes. */
readonly change = new EventEmitter<Direction>();
readonly change: EventEmitter<Direction> = new EventEmitter<Direction>();

constructor(@Optional() @Inject(DIR_DOCUMENT) _document?: any) {
if (_document) {
Expand Down
3 changes: 2 additions & 1 deletion src/cdk/observers/observe-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export class CdkObserveContent implements AfterContentInit, OnDestroy {
private _observer: MutationObserver | null;

/** Event emitted for each change in the element's content. */
@Output('cdkObserveContent') event = new EventEmitter<MutationRecord[]>();
@Output('cdkObserveContent') event: EventEmitter<MutationRecord[]> =
new EventEmitter<MutationRecord[]>();

/** Used for debouncing the emitted values to the observeContent event. */
private _debouncer = new Subject<MutationRecord[]>();
Expand Down
79 changes: 37 additions & 42 deletions src/cdk/overlay/overlay-directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,11 @@ export class CdkOverlayOrigin {
exportAs: 'cdkConnectedOverlay'
})
export class CdkConnectedOverlay implements OnDestroy, OnChanges {
private _overlayRef: OverlayRef;
private _templatePortal: TemplatePortal;
private _hasBackdrop = false;
private _backdropSubscription = Subscription.EMPTY;
private _positionSubscription = Subscription.EMPTY;
private _offsetX: number = 0;
private _offsetY: number = 0;
private _position: ConnectedPositionStrategy;
private _overlayRef: OverlayRef;
private _templatePortal: TemplatePortal;
private _backdropSubscription = Subscription.EMPTY;
private _positionSubscription = Subscription.EMPTY;
private _position: ConnectedPositionStrategy;

/** Origin for the connected overlay. */
@Input('cdkConnectedOverlayOrigin') origin: CdkOverlayOrigin;
Expand All @@ -112,22 +109,24 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
/** The offset in pixels for the overlay connection point on the x-axis */
@Input('cdkConnectedOverlayOffsetX')
get offsetX(): number { return this._offsetX; }
set offsetX(offsetX: number) {
this._offsetX = offsetX;
set offsetX(value: number) {
this._offsetX = value;
if (this._position) {
this._position.withOffsetX(offsetX);
this._position.withOffsetX(value);
}
}
private _offsetX: number = 0;

/** The offset in pixels for the overlay connection point on the y-axis */
@Input('cdkConnectedOverlayOffsetY')
get offsetY() { return this._offsetY; }
set offsetY(offsetY: number) {
this._offsetY = offsetY;
get offsetY(): number { return this._offsetY; }
set offsetY(value: number) {
this._offsetY = value;
if (this._position) {
this._position.withOffsetY(offsetY);
this._position.withOffsetY(value);
}
}
private _offsetY: number = 0;

/** The width of the overlay panel. */
@Input('cdkConnectedOverlayWidth') width: number | string;
Expand All @@ -153,118 +152,118 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {

/** Whether or not the overlay should attach a backdrop. */
@Input('cdkConnectedOverlayHasBackdrop')
get hasBackdrop() { return this._hasBackdrop; }
set hasBackdrop(value: any) { this._hasBackdrop = coerceBooleanProperty(value); }
get hasBackdrop(): boolean { return this._hasBackdrop; }
set hasBackdrop(value: boolean) { this._hasBackdrop = coerceBooleanProperty(value); }
private _hasBackdrop = false;

/**
* @deprecated
* @deletion-target 6.0.0
*/
@Input('origin')
get _deprecatedOrigin(): CdkOverlayOrigin { return this.origin; }
set _deprecatedOrigin(_origin: CdkOverlayOrigin) { this.origin = _origin; }
set _deprecatedOrigin(value: CdkOverlayOrigin) { this.origin = value; }

/**
* @deprecated
* @deletion-target 6.0.0
*/
@Input('positions')
get _deprecatedPositions(): ConnectionPositionPair[] { return this.positions; }
set _deprecatedPositions(_positions: ConnectionPositionPair[]) { this.positions = _positions; }
set _deprecatedPositions(value: ConnectionPositionPair[]) { this.positions = value; }

/**
* @deprecated
* @deletion-target 6.0.0
*/
@Input('offsetX')
get _deprecatedOffsetX(): number { return this.offsetX; }
set _deprecatedOffsetX(_offsetX: number) { this.offsetX = _offsetX; }
set _deprecatedOffsetX(value: number) { this.offsetX = value; }

/**
* @deprecated
* @deletion-target 6.0.0
*/
@Input('offsetY')
get _deprecatedOffsetY(): number { return this.offsetY; }
set _deprecatedOffsetY(_offsetY: number) { this.offsetY = _offsetY; }
set _deprecatedOffsetY(value: number) { this.offsetY = value; }

/**
* @deprecated
* @deletion-target 6.0.0
*/
@Input('width')
get _deprecatedWidth(): number | string { return this.width; }
set _deprecatedWidth(_width: number | string) { this.width = _width; }
set _deprecatedWidth(value: number | string) { this.width = value; }

/**
* @deprecated
* @deletion-target 6.0.0
*/
@Input('height')
get _deprecatedHeight(): number | string { return this.height; }
set _deprecatedHeight(_height: number | string) { this.height = _height; }
set _deprecatedHeight(value: number | string) { this.height = value; }

/**
* @deprecated
* @deletion-target 6.0.0
*/
@Input('minWidth')
get _deprecatedMinWidth(): number | string { return this.minWidth; }
set _deprecatedMinWidth(_minWidth: number | string) { this.minWidth = _minWidth; }
set _deprecatedMinWidth(value: number | string) { this.minWidth = value; }

/**
* @deprecated
* @deletion-target 6.0.0
*/
@Input('minHeight')
get _deprecatedMinHeight(): number | string { return this.minHeight; }
set _deprecatedMinHeight(_minHeight: number | string) { this.minHeight = _minHeight; }
set _deprecatedMinHeight(value: number | string) { this.minHeight = value; }

/**
* @deprecated
* @deletion-target 6.0.0
*/
@Input('backdropClass')
get _deprecatedBackdropClass(): string { return this.backdropClass; }
set _deprecatedBackdropClass(_backdropClass: string) { this.backdropClass = _backdropClass; }
set _deprecatedBackdropClass(value: string) { this.backdropClass = value; }

/**
* @deprecated
* @deletion-target 6.0.0
*/
@Input('scrollStrategy')
get _deprecatedScrollStrategy(): ScrollStrategy { return this.scrollStrategy; }
set _deprecatedScrollStrategy(_scrollStrategy: ScrollStrategy) {
this.scrollStrategy = _scrollStrategy;
}
set _deprecatedScrollStrategy(value: ScrollStrategy) { this.scrollStrategy = value; }

/**
* @deprecated
* @deletion-target 6.0.0
*/
@Input('open')
get _deprecatedOpen(): boolean { return this.open; }
set _deprecatedOpen(_open: boolean) { this.open = _open; }
set _deprecatedOpen(value: boolean) { this.open = value; }

/**
* @deprecated
* @deletion-target 6.0.0
*/
@Input('hasBackdrop')
get _deprecatedHasBackdrop() { return this.hasBackdrop; }
set _deprecatedHasBackdrop(_hasBackdrop: any) { this.hasBackdrop = _hasBackdrop; }
get _deprecatedHasBackdrop(): boolean { return this.hasBackdrop; }
set _deprecatedHasBackdrop(value: boolean) { this.hasBackdrop = value; }

/** Event emitted when the backdrop is clicked. */
@Output() backdropClick = new EventEmitter<void>();
@Output() backdropClick: EventEmitter<void> = new EventEmitter<void>();

/** Event emitted when the position has changed. */
@Output() positionChange = new EventEmitter<ConnectedOverlayPositionChange>();
@Output() positionChange: EventEmitter<ConnectedOverlayPositionChange> =
new EventEmitter<ConnectedOverlayPositionChange>();

/** Event emitted when the overlay has been attached. */
@Output() attach = new EventEmitter<void>();
@Output() attach: EventEmitter<void> = new EventEmitter<void>();

/** Event emitted when the overlay has been detached. */
@Output() detach = new EventEmitter<void>();
@Output() detach: EventEmitter<void> = new EventEmitter<void>();

// TODO(jelbourn): inputs for size, scroll behavior, animation, etc.

Expand All @@ -278,14 +277,10 @@ export class CdkConnectedOverlay implements OnDestroy, OnChanges {
}

/** The associated overlay reference. */
get overlayRef(): OverlayRef {
return this._overlayRef;
}
get overlayRef(): OverlayRef { return this._overlayRef; }

/** The element's layout direction. */
get dir(): Direction {
return this._dir ? this._dir.value : 'ltr';
}
get dir(): Direction { return this._dir ? this._dir.value : 'ltr'; }

ngOnDestroy() {
this._destroyOverlay();
Expand Down
6 changes: 3 additions & 3 deletions src/cdk/overlay/overlay-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,20 @@ export class OverlayRef implements PortalOutlet {
}

/** Updates the position of the overlay based on the position strategy. */
updatePosition() {
updatePosition(): void {
if (this._config.positionStrategy) {
this._config.positionStrategy.apply();
}
}

/** Update the size properties of the overlay. */
updateSize(sizeConfig: OverlaySizeConfig) {
updateSize(sizeConfig: OverlaySizeConfig): void {
this._config = {...this._config, ...sizeConfig};
this._updateElementSize();
}

/** Sets the LTR/RTL direction for the overlay. */
setDirection(dir: Direction) {
setDirection(dir: Direction): void {
this._config = {...this._config, direction: dir};
this._updateElementDirection();
}
Expand Down
8 changes: 3 additions & 5 deletions src/cdk/overlay/position/connected-position-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ export class ConnectedPositionStrategy implements PositionStrategy {
private _resizeSubscription = Subscription.EMPTY;

/** Whether the we're dealing with an RTL context */
get _isRtl() {
return this._dir === 'rtl';
}
get _isRtl() { return this._dir === 'rtl'; }

/** Ordered list of preferred positions, from most to least desirable. */
_preferredPositions: ConnectionPositionPair[] = [];
Expand Down Expand Up @@ -105,13 +103,13 @@ export class ConnectedPositionStrategy implements PositionStrategy {
}

/** Disposes all resources used by the position strategy. */
dispose() {
dispose(): void {
this._applied = false;
this._resizeSubscription.unsubscribe();
}

/** @docs-private */
detach() {
detach(): void {
this._applied = false;
this._resizeSubscription.unsubscribe();
}
Expand Down
Loading