Skip to content

Commit

Permalink
refactor: compat with TypeScript 4.6+
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Aug 31, 2022
1 parent 19ebd6f commit c9b4a89
Show file tree
Hide file tree
Showing 41 changed files with 72 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -33,3 +33,4 @@ dist
.ssl
RELEASE_BODY.md
*tsbuildinfo
.angular
4 changes: 3 additions & 1 deletion projects/addon-commerce/utils/get-currency-symbol.ts
@@ -1,7 +1,9 @@
import {TuiCurrency, TuiCurrencyCode} from '@taiga-ui/addon-commerce/enums';
import {TuiCurrencyVariants} from '@taiga-ui/addon-commerce/types';

export function tuiGetCurrencySymbol(currency: TuiCurrencyVariants): string | null {
export function tuiGetCurrencySymbol(
currency?: TuiCurrencyVariants | null,
): string | null {
switch (currency) {
case TuiCurrency.Ruble:
case TuiCurrencyCode.Ruble:
Expand Down
Expand Up @@ -89,7 +89,7 @@ export class TuiDocNavigationComponent {
}

get canOpen(): boolean {
return this.search.value.length > 2;
return (this.search.value?.length ?? 0) > 2;
}

get itemsWithoutSections(): TuiDocPages {
Expand Down
Expand Up @@ -3,7 +3,7 @@ import {Directive, Inject, Input, TemplateRef} from '@angular/core';
@Directive({
selector: `[tuiHead]`,
})
export class TuiHeadDirective<T extends Record<any, any>> {
export class TuiHeadDirective<T> {
@Input()
tuiHead!: keyof T;

Expand Down
9 changes: 7 additions & 2 deletions projects/addon-table/components/table/tr/tr.component.ts
Expand Up @@ -6,7 +6,7 @@ import {
Inject,
QueryList,
} from '@angular/core';
import {EMPTY_QUERY} from '@taiga-ui/cdk';
import {EMPTY_QUERY, tuiPure} from '@taiga-ui/cdk';
import {map, startWith} from 'rxjs/operators';

import {TuiCellDirective} from '../directives/cell.directive';
Expand All @@ -20,7 +20,7 @@ import {TuiTbodyComponent} from '../tbody/tbody.component';
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [TUI_TABLE_PROVIDER],
})
export class TuiTrComponent<T extends Record<string, any>> {
export class TuiTrComponent<T> {
@ContentChildren(forwardRef(() => TuiCellDirective))
private readonly cells: QueryList<TuiCellDirective> = EMPTY_QUERY;

Expand Down Expand Up @@ -48,4 +48,9 @@ export class TuiTrComponent<T extends Record<string, any>> {
@Inject(forwardRef(() => TuiTbodyComponent))
private readonly body: TuiTbodyComponent<T>,
) {}

@tuiPure
keyof$<U>(key: any): keyof U {
return key.toString() as keyof U;
}
}
4 changes: 2 additions & 2 deletions projects/addon-table/components/table/tr/tr.template.html
@@ -1,14 +1,14 @@
<ng-container *ngIf="cells$ | async as items">
<ng-container
*ngFor="let key of table.columns"
[ngTemplateOutlet]="items[key.toString()]?.template || plain"
[ngTemplateOutlet]="items[keyof$(key)]?.template || plain"
>
<ng-template #plain>
<td
*ngIf="item$ | async as item"
tuiTd
>
{{ item[key.toString()] }}
{{ item[keyof$(key)] }}
</td>
</ng-template>
</ng-container>
Expand Down
3 changes: 2 additions & 1 deletion projects/cdk/schematics/ng-add/steps/add-taiga-icons.ts
@@ -1,6 +1,7 @@
import {JsonArray} from '@angular-devkit/core';
import {Rule, Tree} from '@angular-devkit/schematics';
import {updateWorkspace} from '@schematics/angular/utility/workspace';
import {WorkspaceDefinition} from '@angular-devkit/core/src/workspace';
import {getProject} from '../../utils/get-project';
import {getProjectTargetOptions} from '../../utils/get-project-target-options';
import {Schema} from '../schema';
Expand All @@ -19,7 +20,7 @@ export function addTaigaIcons(options: Schema): Rule {

export function addTaigaAssetsToAngularJson(options: Schema): Rule {
return updateWorkspace(workspace => {
const project = getProject(options, workspace);
const project = getProject(options, workspace as unknown as WorkspaceDefinition);

if (project) {
const targetOptions = getProjectTargetOptions(project, 'build');
Expand Down
3 changes: 2 additions & 1 deletion projects/cdk/schematics/ng-add/steps/add-taiga-modules.ts
Expand Up @@ -20,11 +20,12 @@ import {
} from '../constants/modules';
import {Schema} from '../schema';
import {addUniqueImport} from '../../utils/add-unique-import';
import {WorkspaceDefinition} from "@angular-devkit/core/src/workspace";

export function addTaigaModules(options: Schema): Rule {
return async (tree: Tree, context: SchematicContext) => {
const workspace = await getWorkspace(tree);
const project = getProject(options, workspace);
const project = getProject(options, workspace as unknown as WorkspaceDefinition);

if (!project) {
context.logger.warn(
Expand Down
3 changes: 2 additions & 1 deletion projects/cdk/schematics/ng-add/steps/wrap-with-tui-root.ts
Expand Up @@ -14,11 +14,12 @@ import {
import {getProject} from '../../utils/get-project';
import {getProjectTargetOptions} from '../../utils/get-project-target-options';
import {Schema} from '../schema';
import {WorkspaceDefinition} from "@angular-devkit/core/src/workspace";

export function wrapWithTuiRootComponent(options: Schema): Rule {
return async (tree: Tree, context: SchematicContext) => {
const workspace = await getWorkspace(tree);
const project = getProject(options, workspace);
const project = getProject(options, workspace as unknown as WorkspaceDefinition);

if (!project) {
return;
Expand Down
Expand Up @@ -5,6 +5,7 @@ import {getProject} from '../../utils/get-project';
import {Schema} from '../../ng-add/schema';
import {getPackageJsonDependency, getSourceFiles} from 'ng-morph';
import {isInvalidAngularJson} from '../../utils/angular-json-manipulations';
import {WorkspaceDefinition} from "@angular-devkit/core/src/workspace";

const PROPRIETARY_TDS_ICON_ASSETS = {
glob: '**/*',
Expand Down Expand Up @@ -45,7 +46,7 @@ export function migrateTaigaProprietaryIcons(options: Schema): Rule {
return;
}

const project = getProject(options, workspace);
const project = getProject(options, workspace as unknown as WorkspaceDefinition);

if (!project) {
context.logger.warn(
Expand Down
3 changes: 2 additions & 1 deletion projects/cdk/schematics/utils/angular-json-manipulations.ts
Expand Up @@ -4,6 +4,7 @@ import {getProject} from './get-project';
import {getProjectTargetOptions} from './get-project-target-options';
import {JsonArray} from '@angular-devkit/core';
import {getWorkspace, updateWorkspace} from '@schematics/angular/utility/workspace';
import {WorkspaceDefinition} from "@angular-devkit/core/src/workspace";
import {addPackageJsonDependency} from 'ng-morph';
import {TAIGA_VERSION} from '../ng-add/constants/versions';
import {NodePackageInstallTask} from '@angular-devkit/schematics/tasks';
Expand All @@ -29,7 +30,7 @@ export function addStylesToAngularJson(
tree?: Tree,
): Rule {
return updateWorkspace(workspace => {
const project = getProject(options, workspace);
const project = getProject(options, workspace as unknown as WorkspaceDefinition);

if (!project) {
context.logger.warn(
Expand Down
12 changes: 6 additions & 6 deletions projects/cdk/schematics/utils/get-project.ts
@@ -1,13 +1,13 @@
import {workspaces} from '@angular-devkit/core';
import {Schema} from '../ng-add/schema';
import {ProjectDefinition, WorkspaceDefinition} from "@angular-devkit/core/src/workspace";



export function getProject(
options: Schema,
workspace: workspaces.WorkspaceDefinition,
): workspaces.ProjectDefinition | undefined {
workspace: WorkspaceDefinition,
): ProjectDefinition | undefined {
const projectName =
options.project || workspace.extensions.defaultProject?.toString() || '';
const project = workspace.projects.get(projectName);

return project;
return workspace.projects.get(projectName);
}
2 changes: 1 addition & 1 deletion projects/demo/src/modules/app/app.routes.ts
Expand Up @@ -1595,7 +1595,7 @@ export const ROUTES = [
@NgModule({
imports: [
RouterModule.forRoot(ROUTES, {
initialNavigation: `enabled`,
initialNavigation: `enabledBlocking`,
scrollPositionRestoration: `top`,
}),
],
Expand Down
Expand Up @@ -30,7 +30,7 @@ export class TuiDataListExample5 {
TuiDay.currentLocal().append({year: 1}),
);

get testValue(): string {
get testValue(): string | null | undefined {
return this.testForm.get(`testValue`)?.value;
}

Expand Down
Expand Up @@ -5,4 +5,4 @@
></tui-editor>

<h4>HTML:</h4>
<tui-editor-socket [content]="control.value"></tui-editor-socket>
<tui-editor-socket [content]="control.value || ''"></tui-editor-socket>
Expand Up @@ -6,7 +6,7 @@

<h4>HTML:</h4>
<tui-editor-socket
[content]="control.value"
[content]="control.value || ''"
(imagePreview)="preview.showImage($event)"
>
<image-preview-example #preview></image-preview-example>
Expand Down
Expand Up @@ -8,7 +8,7 @@
<h4>HTML:</h4>
<tui-editor-socket
class="socket"
[content]="control.value"
[content]="control.value || ''"
></tui-editor-socket>

<h4>Text:</h4>
Expand Down
Expand Up @@ -5,7 +5,7 @@
></tui-editor>

<h4>HTML:</h4>
<tui-editor-socket [content]="control.value"></tui-editor-socket>
<tui-editor-socket [content]="control.value || ''"></tui-editor-socket>

<h4>Text:</h4>
<p>{{ control.value }}</p>
Expand Up @@ -5,7 +5,7 @@
></tui-editor>

<h4>HTML:</h4>
<tui-editor-socket [content]="control.value"></tui-editor-socket>
<tui-editor-socket [content]="control.value || ''"></tui-editor-socket>

<h4>Text:</h4>
<p>{{ control.value }}</p>
Expand Up @@ -5,7 +5,7 @@
></tui-editor>

<h4>HTML:</h4>
<tui-editor-socket [content]="control.value"></tui-editor-socket>
<tui-editor-socket [content]="control.value || ''"></tui-editor-socket>

<h4>Text:</h4>
<p>{{ control.value }}</p>
Expand Up @@ -17,13 +17,13 @@ export class TuiInputCardExample1 {
});

get card(): string | null {
const value: string = this.form.get(`card`)!.value;
const value: string | null | undefined = this.form.get(`card`)?.value;

if (value.length < 7) {
if ((value?.length ?? 0) < 7) {
return null;
}

switch (value.charAt(0)) {
switch (value?.charAt(0)) {
case `0`:
case `1`:
case `2`:
Expand Down
Expand Up @@ -20,7 +20,7 @@ export class TuiInputFilesExample2 {

removeFile({name}: File): void {
this.control.setValue(
this.control.value.filter((current: File) => current.name !== name),
this.control.value?.filter((current: File) => current.name !== name) ?? [],
);
}

Expand Down
Expand Up @@ -17,10 +17,10 @@ export class TuiInputSliderExample2 {
readonly min = 0;

increase(): void {
this.control.patchValue(Math.min(this.control.value + 20, this.max));
this.control.patchValue(Math.min((this.control?.value ?? 0) + 20, this.max));
}

decrease(): void {
this.control.patchValue(Math.max(this.control.value - 20, this.min));
this.control.patchValue(Math.max((this.control?.value ?? 0) - 20, this.min));
}
}
Expand Up @@ -42,7 +42,7 @@ export class TuiInputTagExample4 {
readonly control = new FormControl([], createControlValidator(tagValidator));

get filtered(): readonly string[] {
return this.filterBy(this.search, this.control.value);
return this.filterBy(this.search, this.control.value ?? []);
}

@tuiPure
Expand Down
Expand Up @@ -125,11 +125,11 @@ export class TuiInputExample4 {
get card(): string | null {
const value = this.testForm.get(`card`)!.value;

if (value.length < 7) {
if ((value?.length ?? 0) < 7) {
return null;
}

switch (value.charAt(0)) {
switch (value?.charAt(0)) {
case `0`:
case `1`:
case `2`:
Expand All @@ -152,7 +152,7 @@ export class TuiInputExample4 {
return (
this.lastUser !== null &&
this.lastUser.toString().toLowerCase() ===
this.testForm.get(`user`)!.value.toLowerCase()
this.testForm.get(`user`)?.value?.toLowerCase()
);
}

Expand Down
Expand Up @@ -42,7 +42,7 @@ export class TuiInputExample8 {
readonly items$ = this.control.valueChanges.pipe(
startWith(``),
switchMap(value =>
this.request(value).pipe(
this.request(value ?? ``).pipe(
map(response => {
if (response.length === 1 && String(response[0]) === value) {
this.onClick(response[0]);
Expand Down
Expand Up @@ -61,7 +61,7 @@ export class TuiMobileCalendarExample1 {
return !this.control.value;
}

getParsed(value: TuiDay, months: string[]): string {
getParsed(value: TuiDay | null, months: string[]): string {
if (!value) {
return `Choose a date`;
}
Expand Down
2 changes: 1 addition & 1 deletion projects/demo/src/modules/utils/format/examples/1/index.ts
Expand Up @@ -19,6 +19,6 @@ export class TuiFormatExample1 {
get px(): string {
const {value} = this.parametersForm.value;

return tuiPx(value);
return tuiPx(value ?? 0);
}
}
2 changes: 1 addition & 1 deletion projects/demo/src/modules/utils/format/examples/4/index.ts
Expand Up @@ -19,6 +19,6 @@ export class TuiFormatExample4 {
get capitalized(): string {
const {value} = this.parametersForm.value;

return tuiCapitalize(value);
return tuiCapitalize(value ?? ``);
}
}
2 changes: 1 addition & 1 deletion projects/demo/src/modules/utils/format/examples/5/index.ts
Expand Up @@ -21,6 +21,6 @@ export class TuiFormatExample5 {
get formattedPhone(): string {
const {value, countryCode, phoneMask} = this.parametersForm.value;

return tuiFormatPhone(value, countryCode, phoneMask);
return tuiFormatPhone(value ?? ``, countryCode ?? ``, phoneMask ?? ``);
}
}
8 changes: 4 additions & 4 deletions projects/demo/src/modules/utils/format/examples/6/index.ts
Expand Up @@ -23,10 +23,10 @@ export class TuiFormatExample6 {
const {value, decimalLimit, decimalSeparator, thousandSeparator} =
this.parametersForm.value;

return tuiFormatNumber(value, {
decimalLimit,
decimalSeparator,
thousandSeparator,
return tuiFormatNumber(value ?? 123456.789, {
decimalLimit: decimalLimit ?? 2,
decimalSeparator: decimalSeparator ?? `.`,
thousandSeparator: thousandSeparator ?? ` `,
});
}
}
6 changes: 3 additions & 3 deletions projects/demo/src/modules/utils/math/examples/1/index.ts
Expand Up @@ -20,18 +20,18 @@ export class TuiMathExample1 {
get rounded(): number {
const {value, precision} = this.parametersForm.value;

return tuiRound(value, precision);
return tuiRound(value ?? 1.005, precision ?? 2);
}

get floored(): number {
const {value, precision} = this.parametersForm.value;

return tuiFloor(value, precision);
return tuiFloor(value ?? 1.005, precision ?? 2);
}

get ceiled(): number {
const {value, precision} = this.parametersForm.value;

return tuiCeil(value, precision);
return tuiCeil(value ?? 1.005, precision ?? 2);
}
}

0 comments on commit c9b4a89

Please sign in to comment.