Skip to content

Commit

Permalink
refactor: enable strict mode for spell, smart-scripts (#2987)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescoBorzi authored May 24, 2024
1 parent 1e053d0 commit 248839e
Show file tree
Hide file tree
Showing 21 changed files with 48 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export class SaiSearchEntityComponent {
readonly SAI_SEARCH_TYPES_KEYS = getEnumKeys(SAI_TYPES);

readonly form = new FormGroup<ModelForm<Partial<SmartScripts>>>({
source_type: new FormControl<number>(null, [Validators.required]),
entryorguid: new FormControl<number>(null, [Validators.required]),
source_type: new FormControl<number>(null as any, [Validators.required]) as FormControl<number>,
entryorguid: new FormControl<number>(null as any, [Validators.required]) as FormControl<number>,
});

get isTypeCreatureSelected(): boolean {
Expand All @@ -43,15 +43,15 @@ export class SaiSearchEntityComponent {
}

get sourceTypeControl(): FormControl<number> {
return this.form.controls.source_type;
return this.form.controls.source_type as FormControl<number>;
}

get entryOrGuidControl(): FormControl<number> {
return this.form.controls.entryorguid;
return this.form.controls.entryorguid as FormControl<number>;
}

onSelectedTypeChange() {
this.entryOrGuidControl.setValue(null);
this.entryOrGuidControl.setValue(null as any);
}

onEdit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ describe('SaiSearchExisting integration tests', () => {
const row1 = page.getDatatableRowExternal(1);
const row2 = page.getDatatableRowExternal(2);

expect(row0.innerText).toContain(results[0].entryorguid.toString());
expect(row1.innerText).toContain(results[1].entryorguid.toString());
expect(row2.innerText).toContain(results[2].entryorguid.toString());
expect(row0.innerText).toContain(results[0].entryorguid?.toString() as string);
expect(row1.innerText).toContain(results[1].entryorguid?.toString() as string);
expect(row2.innerText).toContain(results[2].entryorguid?.toString() as string);

page.clickElement(page.getDatatableCellExternal(1, 1));

Expand Down
4 changes: 2 additions & 2 deletions libs/features/smart-scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"target": "es2022",
"useDefineForClassFields": false,
"forceConsistentCasingInFileNames": true,
// "strict": true,
// "noImplicitOverride": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ describe('SelectSpell integration tests', () => {
const row1 = page.getDatatableRowExternal(1);
const row2 = page.getDatatableRowExternal(2);

expect(row0.innerText).toContain(results[0][SPELL_DBC_NAME]);
expect(row1.innerText).toContain(results[1][SPELL_DBC_NAME]);
expect(row2.innerText).toContain(results[2][SPELL_DBC_NAME]);
expect(row0.innerText).toContain(results[0][SPELL_DBC_NAME] as string);
expect(row1.innerText).toContain(results[1][SPELL_DBC_NAME] as string);
expect(row2.innerText).toContain(results[2][SPELL_DBC_NAME] as string);

page.clickElement(page.getDatatableCellExternal(1, 1));

expect(navigateSpy).toHaveBeenCalledTimes(1);
expect(navigateSpy).toHaveBeenCalledWith(['spell/spell-dbc']);
page.expectTopBarEditing(results[1][SPELL_DBC_ID], results[1][SPELL_DBC_NAME]);
page.expectTopBarEditing(results[1][SPELL_DBC_ID] as number, results[1][SPELL_DBC_NAME] as string);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('SpellDbcBaseComponent', () => {
})
class TestHostComponent {
@ViewChild(SpellDbcBaseComponent) child!: SpellDbcBaseComponent;
form: FormGroup<ModelForm<SpellDbc>>;
form!: FormGroup<ModelForm<SpellDbc>>;
}

const fields: string[] = [
Expand Down Expand Up @@ -117,7 +117,7 @@ describe('SpellDbcBaseComponent', () => {
const { page, form } = setup();

for (const field of fields) {
form.get(field).setValue(createMockVal(field));
form.get(field)?.setValue(createMockVal(field));
}
page.detectChanges();

Expand All @@ -136,7 +136,7 @@ describe('SpellDbcBaseComponent', () => {
page.detectChanges();

for (const field of fields) {
expect(form.get(field).value).toEqual(createMockVal(field));
expect(form.get(field)?.value).toEqual(createMockVal(field));
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ export class SpellDbcBaseComponent {
readonly SPELL_DBC_DAMAGE_CLASS = SPELL_DBC_DAMAGE_CLASS;
readonly SPELL_DBC_PREVENTION_TYPE = SPELL_DBC_PREVENTION_TYPE;

@Input() formGroup: FormGroup<ModelForm<SpellDbc>>;
@Input({ required: true }) formGroup!: FormGroup<ModelForm<SpellDbc>>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('SpellDbcEffectsComponent', () => {
})
class TestHostComponent {
@ViewChild(SpellDbcEffectsComponent) child!: SpellDbcEffectsComponent;
form: FormGroup<ModelForm<SpellDbc>>;
form!: FormGroup<ModelForm<SpellDbc>>;
}

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ export class SpellDbcEffectsComponent {
readonly SPELL_DBC_TARGETS = SPELL_DBC_TARGETS;
readonly SPELL_DBC_PROC_FLAGS = SPELL_DBC_PROC_FLAGS;

@Input() formGroup: FormGroup<ModelForm<SpellDbc>>;
@Input({ required: true }) formGroup!: FormGroup<ModelForm<SpellDbc>>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ describe('SpellDbcSpellEffectComponent', () => {
})
class TestHostComponent {
@ViewChild(SpellDbcSpellEffectComponent) child!: SpellDbcSpellEffectComponent;
form: FormGroup<ModelForm<SpellDbc>>;
index: number;
form!: FormGroup<ModelForm<SpellDbc>>;
index!: number;
}

beforeEach(async () => {
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('SpellDbcSpellEffectComponent', () => {
host.index = testIndex;

for (const field of SPELL_DBC_SPELL_EFFECT_FIELDS) {
form.get(`${field}_${testIndex}`).setValue(createMockVal(field));
form.get(`${field}_${testIndex}`)?.setValue(createMockVal(field));
}
page.detectChanges();
await page.whenStable();
Expand All @@ -108,7 +108,7 @@ describe('SpellDbcSpellEffectComponent', () => {
await page.whenStable();

for (const field of SPELL_DBC_SPELL_EFFECT_FIELDS) {
expect(form.get(`${field}_${testIndex}`).value).toEqual(createMockVal(field));
expect(form.get(`${field}_${testIndex}`)?.value).toEqual(createMockVal(field));
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import { TranslateModule } from '@ngx-translate/core';
imports: [FormsModule, ReactiveFormsModule, TranslateModule, SingleValueSelectorBtnComponent, TooltipModule, FlagsSelectorBtnComponent],
})
export class SpellDbcSpellEffectComponent {
@Input() formGroup: FormGroup<ModelForm<SpellDbc>>;
@Input() index: number;
@Input({ required: true }) formGroup!: FormGroup<ModelForm<SpellDbc>>;
@Input({ required: true }) index!: number;

readonly SPELL_MECHANIC = SPELL_MECHANIC;
readonly SPELL_DBC_EFFECT = SPELL_DBC_EFFECT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('SpellDbcFlagsComponent', () => {
})
class TestHostComponent {
@ViewChild(SpellDbcFlagsComponent) child!: SpellDbcFlagsComponent;
form: FormGroup<ModelForm<SpellDbc>>;
form!: FormGroup<ModelForm<SpellDbc>>;
}

beforeEach(async () => {
Expand Down Expand Up @@ -83,7 +83,7 @@ describe('SpellDbcFlagsComponent', () => {
const { page, form } = setup();

for (const field of fields) {
form.get(field).setValue(createMockVal(field));
form.get(field)?.setValue(createMockVal(field));
}
page.detectChanges();

Expand All @@ -102,7 +102,7 @@ describe('SpellDbcFlagsComponent', () => {
page.detectChanges();

for (const field of fields) {
expect(form.get(field).value).toEqual(createMockVal(field));
expect(form.get(field)?.value).toEqual(createMockVal(field));
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ export class SpellDbcFlagsComponent {
readonly SPELL_DBC_STANCES_FLAGS = SPELL_DBC_STANCES_FLAGS;
readonly SPELL_DBC_FACING_FRONT_FLAG = SPELL_DBC_FACING_FRONT_FLAG;

@Input() formGroup: FormGroup<ModelForm<SpellDbc>>;
@Input({ required: true }) formGroup!: FormGroup<ModelForm<SpellDbc>>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('SpellDbcItemsComponent', () => {
})
class TestHostComponent {
@ViewChild(SpellDbcItemsComponent) child!: SpellDbcItemsComponent;
form: FormGroup<ModelForm<SpellDbc>>;
form!: FormGroup<ModelForm<SpellDbc>>;
}

const fields: string[] = [
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('SpellDbcItemsComponent', () => {
const { page, form } = setup();

for (const field of fields) {
form.get(field).setValue(createMockVal(field));
form.get(field)?.setValue(createMockVal(field));
}
page.detectChanges();

Expand All @@ -110,7 +110,7 @@ describe('SpellDbcItemsComponent', () => {
page.detectChanges();

for (const field of fields) {
expect(form.get(field).value).toEqual(createMockVal(field));
expect(form.get(field)?.value).toEqual(createMockVal(field));
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ export class SpellDbcItemsComponent {
readonly SPELL_DBC_INVENTORY_TYPE = SPELL_DBC_INVENTORY_TYPE;
readonly TOTEM_CATEGORY = TOTEM_CATEGORY;

@Input() formGroup: FormGroup<ModelForm<SpellDbc>>;
@Input({ required: true }) formGroup!: FormGroup<ModelForm<SpellDbc>>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('SpellDbcMiscComponent', () => {
})
class TestHostComponent {
@ViewChild(SpellDbcMiscComponent) child!: SpellDbcMiscComponent;
form: FormGroup<ModelForm<SpellDbc>>;
form!: FormGroup<ModelForm<SpellDbc>>;
}

const fields: string[] = [
Expand Down Expand Up @@ -76,7 +76,7 @@ describe('SpellDbcMiscComponent', () => {
const { page, form } = setup();

for (const field of fields) {
form.get(field).setValue(createMockVal(field));
form.get(field)?.setValue(createMockVal(field));
}
page.detectChanges();

Expand All @@ -95,7 +95,7 @@ describe('SpellDbcMiscComponent', () => {
page.detectChanges();

for (const field of fields) {
expect(form.get(field).value).toEqual(createMockVal(field));
expect(form.get(field)?.value).toEqual(createMockVal(field));
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ import { TooltipModule } from 'ngx-bootstrap/tooltip';
imports: [FormsModule, ReactiveFormsModule, TooltipModule, TranslateModule],
})
export class SpellDbcMiscComponent {
@Input() formGroup: FormGroup<ModelForm<SpellDbc>>;
@Input({ required: true }) formGroup!: FormGroup<ModelForm<SpellDbc>>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ describe('SpellDbcLocaleComponent', () => {
})
class TestHostComponent {
@ViewChild(SpellDbcLocaleComponent) child!: SpellDbcLocaleComponent;
form: FormGroup<ModelForm<SpellDbc>>;
locale: Locale;
form!: FormGroup<ModelForm<SpellDbc>>;
locale!: Locale;
}

beforeEach(async () => {
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('SpellDbcLocaleComponent', () => {
host.locale = testLocale;

for (const field of SPELL_DBC_TEXT_FIELDS) {
form.get(`${field}_${testLocale}`).setValue(createMockVal(field));
form.get(`${field}_${testLocale}`)?.setValue(createMockVal(field));
}
page.detectChanges();

Expand All @@ -102,7 +102,7 @@ describe('SpellDbcLocaleComponent', () => {
page.detectChanges();

for (const field of SPELL_DBC_TEXT_FIELDS) {
expect(form.get(`${field}_${testLocale}`).value).toEqual(createMockVal(field));
expect(form.get(`${field}_${testLocale}`)?.value).toEqual(createMockVal(field));
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { Locale, SPELL_DBC_TEXT_FIELDS, SpellDbcTextFieldPrefix } from '../spell
export class SpellDbcLocaleComponent {
readonly FIELDS = SPELL_DBC_TEXT_FIELDS;

@Input() formGroup: FormGroup<ModelForm<SpellDbc>>;
@Input() locale: Locale;
@Input({ required: true }) formGroup!: FormGroup<ModelForm<SpellDbc>>;
@Input({ required: true }) locale!: Locale;

getFieldName(field: SpellDbcTextFieldPrefix): string {
return `${field}_${this.locale}`; // example: NameSubtext_Lang_esES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('SpellDbcTextsComponent', () => {
})
class TestHostComponent {
@ViewChild(SpellDbcTextsComponent) child!: SpellDbcTextsComponent;
form: FormGroup<ModelForm<SpellDbc>>;
form!: FormGroup<ModelForm<SpellDbc>>;
}

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ import { TooltipModule } from 'ngx-bootstrap/tooltip';
})
export class SpellDbcTextsComponent {
readonly LOCALES = LOCALES;
@Input() formGroup: FormGroup<ModelForm<SpellDbc>>;
@Input({ required: true }) formGroup!: FormGroup<ModelForm<SpellDbc>>;
}
4 changes: 2 additions & 2 deletions libs/features/spell/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"target": "es2022",
"useDefineForClassFields": false,
"forceConsistentCasingInFileNames": true,
// "strict": true,
// "noImplicitOverride": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
Expand Down

0 comments on commit 248839e

Please sign in to comment.