Skip to content

Commit

Permalink
chore: enable sticter typescript usage
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Jun 2, 2020
1 parent 0ef8ff0 commit e012d56
Show file tree
Hide file tree
Showing 58 changed files with 999 additions and 1,018 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"rxjs": "^6.0.0"
},
"devDependencies": {
"@1stg/app-config": "^0.5.1",
"@1stg/lib-config": "^0.5.1",
"@1stg/app-config": "^0.5.3",
"@1stg/lib-config": "^0.5.3",
"@1stg/tslint-config": "^0.8.3",
"@angular-devkit/build-angular": "^0.901.1",
"@angular-devkit/core": "^9.1.1",
Expand Down Expand Up @@ -120,6 +120,7 @@
],
"rules": {
"@typescript-eslint/no-misused-promises": 0,
"accessor-pairs": 0,
"prefer-promise-reject-errors": 0
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/accordion/accordion-item/accordion-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class AccordionItemComponent extends CdkAccordionItem
this.opened
.pipe(
startWith(null as void),
filter(() => this.expanded),
filter(() => !!this.expanded),
take(1),
)
.subscribe(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/accordion/accordion.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('AccordionComponent', () => {
fixture.detectChanges();
const accordionItemHeaderEl = fixture.debugElement.query(
By.css('.aui-accordion-item__header-toggle'),
).nativeElement;
).nativeElement as HTMLElement;
expect(accordionItemHeaderEl).not.toBeNull();
expect(
accordionItemHeaderEl.querySelector('use').getAttribute('xlink:href'),
Expand All @@ -31,13 +31,13 @@ describe('AccordionComponent', () => {
fixture.detectChanges();
const accordionItemHeaderEl = fixture.debugElement.query(
By.css('.aui-accordion-item__header'),
).nativeElement;
).nativeElement as HTMLElement;
accordionItemHeaderEl.dispatchEvent(new Event('click'));

fixture.detectChanges();
const accordionContentBodyEl = fixture.debugElement.query(
By.css('.aui-accordion-item__content-body'),
).nativeElement;
).nativeElement as HTMLElement;
expect(accordionContentBodyEl.hidden).toBeFalsy();
});
});
Expand Down
4 changes: 3 additions & 1 deletion src/autocomplete/autocomplete.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export class AutocompleteComponent implements AfterContentInit {
this.hasVisibleSuggestion$,
this.placeholder.changes.pipe(
startWith(this.placeholder),
map(list => !!list.length),
map(
(list: QueryList<AutocompletePlaceholderComponent>) => !!list.length,
),
),
]).pipe(
map(
Expand Down
2 changes: 1 addition & 1 deletion src/checkbox/checkbox-group/checkbox-group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { CheckboxComponent } from '../checkbox.component';
},
],
})
export class CheckboxGroupComponent extends CommonFormControl<any[]> {
export class CheckboxGroupComponent extends CommonFormControl<unknown[]> {
private _trackFn: TrackFn;

@Input()
Expand Down
36 changes: 16 additions & 20 deletions src/checkbox/checkbox.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,49 +35,45 @@ describe('CheckboxComponent', () => {

it('should render correct with click event', () => {
// not-checked => checked
fixture.debugElement
.query(By.css('#checkbox2 input'))
.nativeElement.dispatchEvent(new Event('click'));
(fixture.debugElement.query(By.css('#checkbox2 input'))
.nativeElement as HTMLElement).dispatchEvent(new Event('click'));
fixture.detectChanges();
expect(
fixture.debugElement.query(By.css('#checkbox2 .aui-checkbox'))
.nativeElement.className,
(fixture.debugElement.query(By.css('#checkbox2 .aui-checkbox'))
.nativeElement as HTMLElement).className,
).toContain('isChecked');

// checked => not-checked
fixture.debugElement
.query(By.css('#checkbox1 input'))
.nativeElement.dispatchEvent(new Event('click'));
(fixture.debugElement.query(By.css('#checkbox1 input'))
.nativeElement as HTMLElement).dispatchEvent(new Event('click'));
fixture.detectChanges();
expect(
fixture.debugElement.query(By.css('#checkbox1 .aui-checkbox'))
.nativeElement.className,
(fixture.debugElement.query(By.css('#checkbox1 .aui-checkbox'))
.nativeElement as HTMLElement).className,
).not.toContain('isChecked');

// disabled: checked => checked
fixture.debugElement
.query(By.css('#checkbox3 input'))
.nativeElement.dispatchEvent(new Event('click'));
(fixture.debugElement.query(By.css('#checkbox3 input'))
.nativeElement as HTMLElement).dispatchEvent(new Event('click'));
fixture.detectChanges();
expect(
fixture.debugElement.query(By.css('#checkbox3 .aui-checkbox'))
.nativeElement.className,
(fixture.debugElement.query(By.css('#checkbox3 .aui-checkbox'))
.nativeElement as HTMLElement).className,
).toContain('isChecked');
});

it('should render correct with ngModel', fakeAsync(() => {
fixture.debugElement
.query(By.css('#checkbox4 input'))
.nativeElement.dispatchEvent(new Event('click'));
(fixture.debugElement.query(By.css('#checkbox4 input'))
.nativeElement as HTMLElement).dispatchEvent(new Event('click'));
fixture.detectChanges();
expect(ins.checkedMap.d).toBe(false);
ins.checkedMap.d = true;
fixture.detectChanges();
tick();
fixture.detectChanges();
expect(
fixture.debugElement.query(By.css('#checkbox4 .aui-checkbox'))
.nativeElement.className,
(fixture.debugElement.query(By.css('#checkbox4 .aui-checkbox'))
.nativeElement as HTMLElement).className,
).toContain('isChecked');
}));
});
Expand Down
19 changes: 8 additions & 11 deletions src/checkbox/checkbox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export class CheckboxComponent extends CommonFormControl<boolean>
elRef: ElementRef;

private readonly checkboxGroup: CheckboxGroupComponent;
private _label: any;
private readonly label$$ = new BehaviorSubject<any>(this.label);
private _label: unknown;
private readonly label$$ = new BehaviorSubject(this.label);
private readonly destroy$$ = new Subject<void>();

constructor(
Expand All @@ -80,15 +80,12 @@ export class CheckboxComponent extends CommonFormControl<boolean>
takeUntil(this.destroy$$),
map(([value, label]) => {
if (this.checkboxGroup.trackFn) {
return (
value &&
value.some(v => {
return (
this.checkboxGroup.trackFn(v) ===
this.checkboxGroup.trackFn(label)
);
})
);
return value?.some(v => {
return (
this.checkboxGroup.trackFn(v) ===
this.checkboxGroup.trackFn(label)
);
});
}
return value?.includes(label);
}),
Expand Down
4 changes: 2 additions & 2 deletions src/dialog/confirm-dialog/confirm-dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class ConfirmDialogComponent {
try {
const result = await new Promise(this.config.beforeConfirm);
this.dialogRef.close({ confirm: true, result });
} catch (err) {
} catch {
} finally {
this.waitConfirm = false;
this.cdr.markForCheck();
Expand All @@ -73,7 +73,7 @@ export class ConfirmDialogComponent {
try {
const result = await new Promise(this.config.beforeCancel);
this.dialogRef.close({ confirm: false, result });
} catch (err) {
} catch {
} finally {
this.waitCancel = false;
this.cdr.markForCheck();
Expand Down
2 changes: 1 addition & 1 deletion src/dialog/dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class DialogComponent {
: {};
}

constructor(private readonly elementRef: ElementRef) {}
constructor(private readonly elementRef: ElementRef<HTMLElement>) {}

attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T> {
if (this.portalOutlet.hasAttached()) {
Expand Down
12 changes: 6 additions & 6 deletions src/dialog/dialog.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class DialogService {

const overlayRef = this.createOverlay(config);
const dialogIns = this.attachDialog(overlayRef, config);
const dialogRef = this.attachDialogContent(
const dialogRef = this.attachDialogContent<T, D, R>(
compOrTempRef,
dialogIns,
overlayRef,
Expand Down Expand Up @@ -140,13 +140,13 @@ export class DialogService {
return dialogRef.instance;
}

private attachDialogContent<T>(
private attachDialogContent<T, D, R>(
compOrTempRef: ComponentType<T> | TemplateRef<T>,
dialogIns: DialogComponent,
overlayRef: OverlayRef,
config: DialogConfig,
): DialogRef<T> {
const dialogRef = new DialogRef<T>(
config: DialogConfig<D>,
): DialogRef<T, R> {
const dialogRef = new DialogRef<T, R>(
overlayRef,
dialogIns,
this.scrollDispatcher,
Expand All @@ -155,7 +155,7 @@ export class DialogService {

if (compOrTempRef instanceof TemplateRef) {
dialogIns.attachTemplatePortal(
new TemplatePortal<T>(compOrTempRef, null, {
new TemplatePortal(compOrTempRef, null, {
$implicit: config.data,
} as any),
);
Expand Down
2 changes: 1 addition & 1 deletion src/dialog/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function getClosestDialog(
element: ElementRef,
openDialogs: Array<DialogRef<any>>,
) {
let parent: HTMLElement | null = element.nativeElement.parentElement;
let parent = (element.nativeElement as HTMLElement).parentElement;

while (parent?.tagName !== 'AUI-DIALOG') {
parent = parent.parentElement;
Expand Down
14 changes: 9 additions & 5 deletions src/dropdown/menu/menu-content.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ export class MenuContentDirective implements OnDestroy {
private portal: TemplatePortal;
private outlet: DomPortalOutlet;

private readonly doc: Document;

constructor(
private readonly templateRef: TemplateRef<any>,
private readonly templateRef: TemplateRef<unknown>,
private readonly appRef: ApplicationRef,
private readonly viewContainerRef: ViewContainerRef,
private readonly componentFactoryResolver: ComponentFactoryResolver,
private readonly injector: Injector,
@Inject(DOCUMENT) private readonly document: any,
) {}
@Inject(DOCUMENT) document: any,
) {
this.doc = document;
}

attach(context: any) {
this.detach();
Expand All @@ -35,13 +39,13 @@ export class MenuContentDirective implements OnDestroy {
}
if (!this.outlet) {
this.outlet = new DomPortalOutlet(
this.document.createElement('div'),
this.doc.createElement('div'),
this.componentFactoryResolver,
this.appRef,
this.injector,
);
}
const el: HTMLElement = this.templateRef.elementRef.nativeElement;
const el = this.templateRef.elementRef.nativeElement as HTMLElement;
el.parentNode.insertBefore(this.outlet.outletElement, el);
this.portal.attach(this.outlet, context);
}
Expand Down
24 changes: 12 additions & 12 deletions src/inline-alert/inline-alert.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ describe('InlineAlertComponent', () => {
ins.title = 'text title 1';
fixture.detectChanges();
expect(
fixture.debugElement.query(
(fixture.debugElement.query(
By.css('#inline-alert .aui-inline-alert__title'),
).nativeElement.textContent,
).nativeElement as HTMLElement).textContent,
).toContain('text title 1');

ins.content = 'text content 1';
fixture.detectChanges();
expect(
fixture.debugElement.query(
(fixture.debugElement.query(
By.css('#inline-alert .aui-inline-alert__content'),
).nativeElement.textContent,
).nativeElement as HTMLElement).textContent,
).toContain('text content 1');
});

it('should be closed by click close button', () => {
fixture.debugElement
.query(By.css('#inline-alert .aui-inline-alert__close'))
.nativeElement.click();
(fixture.debugElement.query(
By.css('#inline-alert .aui-inline-alert__close'),
).nativeElement as HTMLElement).click();
fixture.detectChanges();
expect(
fixture.debugElement.query(By.css('#inline-alert aui-inline-alert')),
Expand All @@ -55,9 +55,9 @@ describe('InlineAlertComponent', () => {
ins.inlineAlertRef.close.subscribe(() => {
resolve();
});
fixture.debugElement
.query(By.css('#inline-alert .aui-inline-alert__close'))
.nativeElement.click();
(fixture.debugElement.query(
By.css('#inline-alert .aui-inline-alert__close'),
).nativeElement as HTMLElement).click();
fixture.detectChanges();
});
});
Expand Down Expand Up @@ -92,8 +92,8 @@ describe('InlineAlertComponent', () => {
fixture.componentInstance.type = type;
fixture.detectChanges();
expect(
fixture.debugElement.query(By.css('#inline-alert .aui-inline-alert'))
.nativeElement.className,
(fixture.debugElement.query(By.css('#inline-alert .aui-inline-alert'))
.nativeElement as HTMLElement).className,
).toContain(`aui-inline-alert--${type}`);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/input/input.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class InputComponent {
disabled$ = new BehaviorSubject<boolean>(this.disabled);

constructor(
public elementRef: ElementRef,
public elementRef: ElementRef<HTMLInputElement>,
private readonly renderer: Renderer2,
) {
this.renderer.addClass(this.elementRef.nativeElement, 'aui-input');
Expand Down
10 changes: 5 additions & 5 deletions src/input/tags-input/tags-input.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ export class TagsInputComponent extends CommonFormControl<string[]> {
allowEmpty = false;

@ViewChild('inputRef', { static: true })
inputRef: ElementRef;
inputRef: ElementRef<HTMLInputElement>;

@ViewChild('inputValueMirror', { static: true })
inputValueMirror: ElementRef;
inputValueMirror: ElementRef<HTMLElement>;

snapshot = {
value: [] as string[],
Expand All @@ -82,9 +82,9 @@ export class TagsInputComponent extends CommonFormControl<string[]> {
const size = this.size || ComponentSize.Medium;
return `aui-input ${this.bem.block(size)} ${
this.disabled ? 'isDisabled' : ''
} ${this.focused ? 'isFocused' : ''} ${
this.clearable
} ? 'isClearable' : ''`;
} ${
this.focused ? 'isFocused' : ''
} ${this.clearable.toString()} ? 'isClearable' : ''`;
}

get tagSize() {
Expand Down
6 changes: 3 additions & 3 deletions src/message/base-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export abstract class BaseMessage<
Component extends MessageComponent,
Config extends MessageConfig
> {
wrapperInstance: { elementRef: ElementRef };
wrapperInstance: { elementRef: ElementRef<HTMLElement> };
componentRefs: Array<ComponentRef<Component>> = [];

constructor(
Expand All @@ -52,7 +52,7 @@ export abstract class BaseMessage<
: this.globalConfig.duration[type],
...(content
? { type: config as MessageType, content }
: (config as object)),
: (config as Config)),
} as Config;

this.removeNeedless(mergedConfig.id);
Expand All @@ -69,7 +69,7 @@ export abstract class BaseMessage<
createType(type: MessageType, option: Config | string) {
return typeof option === 'string'
? this.create(type, option)
: this.create({ ...(option as object), type } as Config);
: this.create({ ...option, type } as Config);
}

success(option: Config | string): ComponentRef<Component> {
Expand Down
Loading

0 comments on commit e012d56

Please sign in to comment.