Skip to content

Commit

Permalink
refactor: no inferable type for clean code (#6694)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Feb 8, 2024
1 parent 01cad8b commit 8bdc9d9
Show file tree
Hide file tree
Showing 41 changed files with 57 additions and 71 deletions.
4 changes: 2 additions & 2 deletions projects/addon-charts/utils/control-point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export function tuiControlPoint(
current: TuiPoint,
previous?: TuiPoint,
next?: TuiPoint,
reverse: boolean = false,
smoothing: number = 0.2,
reverse = false,
smoothing = 0.2,
): TuiPoint {
const p = previous || current;
const n = next || current;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Pipe, PipeTransform} from '@angular/core';

@Pipe({name: 'tuiFormatCard'})
export class TuiFormatCardPipe implements PipeTransform {
transform(value: string | null = '', cardPrefilled: boolean = false): string {
transform(value: string | null = '', cardPrefilled = false): string {
return value && !cardPrefilled
? value
.split('')
Expand Down
2 changes: 1 addition & 1 deletion projects/addon-doc/components/demo/demo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class TuiDocDemoComponent implements OnInit {
this.createForm();
}

updateWidth(width: number = NaN): void {
updateWidth(width = NaN): void {
if (!this.resizer || !this.resizeable || !this.content) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {TUI_IS_E2E} from '@taiga-ui/cdk';
export class TuiInspectPipe implements PipeTransform {
constructor(@Inject(TUI_IS_E2E) private readonly isE2E: boolean) {}

transform(value: unknown, depth: number = 2): string {
transform(value: unknown, depth = 2): string {
if (this.isE2E && typeof value === 'function') {
/**
* @description:
Expand Down
4 changes: 2 additions & 2 deletions projects/addon-doc/utils/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function inspectArray(array: readonly unknown[], depth: number): string {
return `[${result}]`;
}

function inspectObject(object: {[key: string]: unknown}, depth: number): string {
function inspectObject(object: Record<string, unknown>, depth: number): string {
if (depth === 0) {
return '{…}';
}
Expand Down Expand Up @@ -76,5 +76,5 @@ export function tuiInspectAny<T>(data: T, depth: number): string {
return inspectArray(data, depth);
}

return inspectObject(data as unknown as {[key: string]: unknown}, depth);
return inspectObject(data as unknown as Record<string, unknown>, depth);
}
2 changes: 1 addition & 1 deletion projects/addon-doc/utils/parse-code-block.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import MarkdownIt from 'markdown-it';
import Token from 'markdown-it/lib/token';

export function tuiTryParseMarkdownCodeBlock(text: string = ''): string[] {
export function tuiTryParseMarkdownCodeBlock(text = ''): string[] {
const tokens: Token[] = new MarkdownIt().parse(text, {});
const result = tokens
.filter(({tag, type}) => tag === 'code' && type === 'fence')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const IOS_CYCLE_HEIGHT = reduceCycle(IOS_CYCLE);

function reduceCycle(
cycle: ReadonlyArray<readonly number[]>,
lastYear: number = 28,
lastMonth: number = 12,
lastYear = 28,
lastMonth = 12,
): number {
return cycle.reduce(
(total, year, yearIndex) =>
Expand Down
5 changes: 1 addition & 4 deletions projects/cdk/date-time/day-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ export class TuiDayRange extends TuiMonthRange {
return `${from}${RANGE_SEPARATOR_CHAR}${to}`;
}

override toString(
dateFormat: TuiDateMode = 'DMY',
dateSeparator: string = '.',
): string {
override toString(dateFormat: TuiDateMode = 'DMY', dateSeparator = '.'): string {
return this.getFormattedDayRange(dateFormat, dateSeparator);
}
}
4 changes: 2 additions & 2 deletions projects/cdk/date-time/day.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export class TuiDay extends TuiMonth {
* @param startFromMonday whether week starts from Monday and not from Sunday
* @return day of week (from 0 to 6)
*/
dayOfWeek(startFromMonday: boolean = true): number {
dayOfWeek(startFromMonday = true): number {
const dayOfWeek = startFromMonday
? this.toLocalNativeDate().getDay() - 1
: this.toLocalNativeDate().getDay();
Expand Down Expand Up @@ -366,7 +366,7 @@ export class TuiDay extends TuiMonth {
}
}

override toString(dateFormat: TuiDateMode = 'DMY', separator: string = '.'): string {
override toString(dateFormat: TuiDateMode = 'DMY', separator = '.'): string {
return this.getFormattedDay(dateFormat, separator);
}

Expand Down
13 changes: 4 additions & 9 deletions projects/cdk/date-time/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export class TuiTime implements TuiTimeLike {
constructor(
readonly hours: number,
readonly minutes: number,
readonly seconds: number = 0,
readonly ms: number = 0,
readonly seconds = 0,
readonly ms = 0,
) {
ngDevMode &&
tuiAssert.assert(
Expand All @@ -37,12 +37,7 @@ export class TuiTime implements TuiTimeLike {
/**
* Checks if time is valid
*/
static isValidTime(
hours: number,
minutes: number,
seconds: number = 0,
ms: number = 0,
): boolean {
static isValidTime(hours: number, minutes: number, seconds = 0, ms = 0): boolean {
return (
Number.isInteger(hours) &&
tuiInRange(hours, 0, HOURS_IN_DAY) &&
Expand Down Expand Up @@ -193,7 +188,7 @@ export class TuiTime implements TuiTimeLike {
);
}

private formatTime(time: number, digits: number = 2): string {
private formatTime(time: number, digits = 2): string {
return String(time).padStart(digits, '0');
}
}
2 changes: 1 addition & 1 deletion projects/cdk/decorators/pure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function decorateMethod(
function decorateGetter(
originalGetter: () => unknown,
propertyKey: string | symbol,
enumerable: boolean = true,
enumerable = true,
): (this: object) => unknown {
return function tuiPureGetterPatched(this: object): unknown {
const value = originalGetter.call(this);
Expand Down
2 changes: 1 addition & 1 deletion projects/cdk/observables/is-alive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
/**
* Operator to set lifespan after which current value is considered obsolete
*/
export function tuiIsAlive(lifespan: number = 0): OperatorFunction<unknown, boolean> {
export function tuiIsAlive(lifespan = 0): OperatorFunction<unknown, boolean> {
return pipe(
switchMap(() => timer(lifespan).pipe(map(ALWAYS_FALSE_HANDLER), startWith(true))),
distinctUntilChanged(),
Expand Down
2 changes: 1 addition & 1 deletion projects/cdk/schematics/ng-update/steps/rename-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function renameType(
from: string,
to?: string,
moduleSpecifier?: string[] | string,
preserveGenerics: boolean = false,
preserveGenerics = false,
): void {
const references = getNamedImportReferences(from, moduleSpecifier);

Expand Down
2 changes: 1 addition & 1 deletion projects/cdk/utils/dom/get-scroll-parent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
export function tuiGetScrollParent(
element: Element | null,
vertical: boolean = true,
vertical = true,
): Element | null {
if (element === null) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion projects/cdk/utils/dom/point-to-client-rect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function tuiPointToClientRect(x: number = 0, y: number = 0): DOMRect {
export function tuiPointToClientRect(x = 0, y = 0): DOMRect {
const rect = {
x,
y,
Expand Down
4 changes: 2 additions & 2 deletions projects/cdk/utils/focus/set-native-mouse-focused.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/
export function tuiSetNativeMouseFocused(
element: Element & HTMLOrSVGElement,
focused: boolean = true,
preventScroll: boolean = false,
focused = true,
preventScroll = false,
): void {
if (!element.ownerDocument) {
return;
Expand Down
8 changes: 4 additions & 4 deletions projects/cdk/utils/math/round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ function calculate(
return Number(`${processedPair[0]}e${Number(processedPair[1]) - precision}`);
}

export function tuiRound(value: number, precision: number = 0): number {
export function tuiRound(value: number, precision = 0): number {
return calculate(value, precision, Math.round);
}

export function tuiCeil(value: number, precision: number = 0): number {
export function tuiCeil(value: number, precision = 0): number {
return calculate(value, precision, Math.ceil);
}

export function tuiFloor(value: number, precision: number = 0): number {
export function tuiFloor(value: number, precision = 0): number {
return calculate(value, precision, Math.floor);
}

export function tuiTrunc(value: number, precision: number = 0): number {
export function tuiTrunc(value: number, precision = 0): number {
return calculate(value, precision, Math.trunc);
}
2 changes: 1 addition & 1 deletion projects/cdk/utils/svg/svg-linear-gradient-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function tuiSvgLinearGradientProcessor(
* TODO: remove in v4.0
* @deprecated
*/
fallback: string = 'rgba(0, 0, 0, 0.7)',
fallback = 'rgba(0, 0, 0, 0.7)',
): TuiSafeHtml {
if (tuiIsString(svg)) {
const uniqueIds = extractLinearGradientIdsFromSvg(svg);
Expand Down
6 changes: 1 addition & 5 deletions projects/core/components/button/button.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import {TuiAppearance} from '@taiga-ui/core/enums';
import {TuiSizeXL, TuiSizeXS} from '@taiga-ui/core/types';

export interface TuiButtonOptions {
readonly appearance:
| TuiAppearance
| string
| keyof Record<TuiAppearance, string>
| null;
readonly appearance: TuiAppearance | string | null;
readonly shape: 'rounded' | 'square' | null;
readonly size: TuiSizeXL | TuiSizeXS;
}
Expand Down
2 changes: 1 addition & 1 deletion projects/core/components/data-list/data-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class TuiDataListComponent<T> implements TuiDataListAccessor<T> {
}
}

getOptions(includeDisabled: boolean = false): readonly T[] {
getOptions(includeDisabled = false): readonly T[] {
return this.options
.filter(({disabled}) => includeDisabled || !disabled)
.map(({value}) => value)
Expand Down
2 changes: 1 addition & 1 deletion projects/core/observables/smart-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {

export function tuiSmartSearch<T>(
getSearchFunction: (search: string) => Observable<readonly T[] | readonly T[][]>,
searchDebounceTimeMs: number = 400,
searchDebounceTimeMs = 400,
): OperatorFunction<string, readonly T[] | readonly T[][] | null> {
return source =>
source.pipe(
Expand Down
2 changes: 1 addition & 1 deletion projects/core/pipes/calendar-sheet/calendar-sheet.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class TuiCalendarSheetPipe implements PipeTransform {

transform(
month: TuiMonth,
showAdjacentDays: boolean = false,
showAdjacentDays = false,
): ReadonlyArray<readonly TuiDay[]> {
if (this.currentMonth?.monthSame(month)) {
return this.currentSheet;
Expand Down
4 changes: 2 additions & 2 deletions projects/core/pipes/format-phone/format-phone.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class TuiFormatPhonePipe implements PipeTransform {
*/
transform(
value: string,
countryCode: string = `${CHAR_PLUS}7`,
phoneMask: string = '(###) ###-##-##',
countryCode = `${CHAR_PLUS}7`,
phoneMask = '(###) ###-##-##',
): string {
ngDevMode &&
tuiAssert.assert(
Expand Down
6 changes: 3 additions & 3 deletions projects/core/utils/miscellaneous/get-border.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const CONTENT_SIZE = 2.5;

export function tuiGetBorder(
hasIcon: boolean,
hasCleaner: boolean = false,
hasTooltip: boolean = false,
hasContent: boolean = false,
hasCleaner = false,
hasTooltip = false,
hasContent = false,
size: TuiSizeL | TuiSizeS = 'm',
): number {
const offset = size === 's' ? 0 : 0.25;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class TuiDocumentationApiPagePO {
}
}

async prepareBeforeScreenshot(hasNot: string = ''): Promise<void> {
async prepareBeforeScreenshot(hasNot = ''): Promise<void> {
await this.hideDocumentation();
await this.hideScrollControls();
await this.hideNavigation();
Expand Down
8 changes: 3 additions & 5 deletions projects/demo/src/modules/app/stackblitz/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ export const prepareLess = (content: string): string =>
"@import '@taiga-ui/core/styles/taiga-ui-local.less';",
);

export const appPrefix = (stringsPart: TemplateStringsArray, path: string = ''): string =>
export const appPrefix = (stringsPart: TemplateStringsArray, path = ''): string =>
`src/app/${stringsPart.join('')}${path}`;

export const stackblitzPrefix = (
stringsPart: TemplateStringsArray,
path: string = '',
): string => `src/app/@stackblitz/${stringsPart.join('')}${path}`;
export const stackblitzPrefix = (stringsPart: TemplateStringsArray, path = ''): string =>
`src/app/@stackblitz/${stringsPart.join('')}${path}`;

export const getSupportFiles = <T extends Record<string, string>>(
files: T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export class User {
readonly firstName: string,
readonly lastName: string,
readonly avatarUrl: string | null = null,
readonly disabled: boolean = false,
readonly disabled = false,
) {}

toString(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class User {
readonly lastName: string,
readonly phone: string,
readonly avatarUrl: string | null = null,
readonly disabled: boolean = false,
readonly disabled = false,
) {}

toString(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class User {
readonly lastName: string,
readonly avatarUrl: string | null = null,
readonly accounts: Account[] = [],
readonly card: string = '',
readonly card = '',
) {}

toString(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class User {
readonly firstName: string,
readonly lastName: string,
readonly avatarUrl: string | null = null,
readonly disabled: boolean = false,
readonly disabled = false,
) {}

toString(): string {
Expand Down
2 changes: 1 addition & 1 deletion projects/kit/components/combo-box/combo-box.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class TuiComboBoxComponent<T>
}
}

private focusInput(preventScroll: boolean = false): void {
private focusInput(preventScroll = false): void {
if (this.nativeFocusableElement) {
this.nativeFocusableElement.focus({preventScroll});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export abstract class AbstractTuiDataListWrapper<T> {
return {$implicit, active: tuiIsNativeFocused(nativeElement)};
}

getOptions(includeDisabled: boolean = false): readonly T[] {
getOptions(includeDisabled = false): readonly T[] {
return this.optionsQuery
.filter(({disabled}) => includeDisabled || !disabled)
.map(({value}) => value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export class TuiInputDateRangeComponent
this.open = !this.open;
}

private focusInput(preventScroll: boolean = false): void {
private focusInput(preventScroll = false): void {
if (this.nativeFocusableElement) {
this.nativeFocusableElement.focus({preventScroll});
}
Expand Down
2 changes: 1 addition & 1 deletion projects/kit/components/input-tag/input-tag.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ export class TuiInputTagComponent
}
}

private focusInput(preventScroll: boolean = false): void {
private focusInput(preventScroll = false): void {
this.nativeFocusableElement?.focus({preventScroll});
}

Expand Down
2 changes: 1 addition & 1 deletion projects/kit/components/input-time/input-time.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export class TuiInputTimeComponent
this.value = increasedTime;
}

private focusInput(preventScroll: boolean = false): void {
private focusInput(preventScroll = false): void {
if (this.nativeFocusableElement) {
this.nativeFocusableElement.focus({preventScroll});
this.close();
Expand Down
Loading

0 comments on commit 8bdc9d9

Please sign in to comment.