From b68b8b3aab757ff110e6b688c3109f50489edb7e Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Wed, 29 Jun 2022 14:00:05 +1000 Subject: [PATCH] Add typing --- libs/common/spec/models/view/attachmentView.spec.ts | 2 +- libs/common/spec/models/view/cipherView.spec.ts | 2 +- libs/common/spec/models/view/loginView.spec.ts | 2 +- libs/common/src/models/view/attachmentView.ts | 2 +- libs/common/src/models/view/cardView.ts | 4 ++-- libs/common/src/models/view/cipherView.ts | 6 +++--- libs/common/src/models/view/fieldView.ts | 2 +- libs/common/src/models/view/identityView.ts | 4 ++-- libs/common/src/models/view/loginUriView.ts | 4 ++-- libs/common/src/models/view/loginView.ts | 2 +- libs/common/src/models/view/passwordHistoryView.ts | 2 +- libs/common/src/models/view/secureNoteView.ts | 2 +- 12 files changed, 17 insertions(+), 17 deletions(-) diff --git a/libs/common/spec/models/view/attachmentView.spec.ts b/libs/common/spec/models/view/attachmentView.spec.ts index d8e4314afc..685aff0555 100644 --- a/libs/common/spec/models/view/attachmentView.spec.ts +++ b/libs/common/spec/models/view/attachmentView.spec.ts @@ -15,7 +15,7 @@ describe("AttachmentView", () => { size: "1000", sizeName: "kb", fileName: "my filename", - key: "encKey", + key: "encKey" as any, }; jest diff --git a/libs/common/spec/models/view/cipherView.spec.ts b/libs/common/spec/models/view/cipherView.spec.ts index cdf458976d..d04893ccf1 100644 --- a/libs/common/spec/models/view/cipherView.spec.ts +++ b/libs/common/spec/models/view/cipherView.spec.ts @@ -52,7 +52,7 @@ describe("CipherView", () => { }); it("fromJSON hydrates new view object", () => { - const mockFromJson = (key: string) => (key + "fromJSON") as any; + const mockFromJson = (key: any) => (key + "fromJSON") as any; jest.spyOn(LoginView, "fromJSON").mockImplementation(mockFromJson); jest.spyOn(AttachmentView, "fromJSON").mockImplementation(mockFromJson); jest.spyOn(FieldView, "fromJSON").mockImplementation(mockFromJson); diff --git a/libs/common/spec/models/view/loginView.spec.ts b/libs/common/spec/models/view/loginView.spec.ts index fed9a3700c..0a89b89acf 100644 --- a/libs/common/spec/models/view/loginView.spec.ts +++ b/libs/common/spec/models/view/loginView.spec.ts @@ -22,7 +22,7 @@ describe("LoginView", () => { jest .spyOn(LoginUriView, "fromJSON") - .mockImplementation((key: string) => (key + "fromJSON") as any); + .mockImplementation((key: any) => (key + "fromJSON") as any); const login = LoginView.fromJSON(parsed); diff --git a/libs/common/src/models/view/attachmentView.ts b/libs/common/src/models/view/attachmentView.ts index 02587e2993..19acd043a8 100644 --- a/libs/common/src/models/view/attachmentView.ts +++ b/libs/common/src/models/view/attachmentView.ts @@ -33,7 +33,7 @@ export class AttachmentView implements View { return 0; } - static fromJSON(obj: any): AttachmentView { + static fromJSON(obj: Partial): AttachmentView { const view = new AttachmentView(); view.id = obj.id; view.url = obj.url; diff --git a/libs/common/src/models/view/cardView.ts b/libs/common/src/models/view/cardView.ts index 7d6209efb5..9537f7daa1 100644 --- a/libs/common/src/models/view/cardView.ts +++ b/libs/common/src/models/view/cardView.ts @@ -80,7 +80,7 @@ export class CardView extends ItemView { return year.length === 2 ? "20" + year : year; } - toJSON() { + toJSON(): Partial { // Needed to serialize getters which are not included by JSON.stringify return { cardholderName: this.cardholderName, @@ -92,7 +92,7 @@ export class CardView extends ItemView { }; } - static fromJSON(obj: any): CardView { + static fromJSON(obj: Partial): CardView { const view = new CardView(); view.cardholderName = obj.cardholderName; view.brand = obj.brand; diff --git a/libs/common/src/models/view/cipherView.ts b/libs/common/src/models/view/cipherView.ts index 0ec283980c..228d568599 100644 --- a/libs/common/src/models/view/cipherView.ts +++ b/libs/common/src/models/view/cipherView.ts @@ -132,8 +132,8 @@ export class CipherView implements View { return this.linkedFieldOptions.get(id)?.i18nKey; } - toJSON(): any { - const result: any = { + toJSON(): Partial { + const result: Partial = { id: this.id, organizationId: this.organizationId, folderId: this.folderId, @@ -176,7 +176,7 @@ export class CipherView implements View { return result; } - static fromJSON(obj: any): CipherView { + static fromJSON(obj: Partial): CipherView { const view = new CipherView(); view.id = obj.id; view.organizationId = obj.organizationId; diff --git a/libs/common/src/models/view/fieldView.ts b/libs/common/src/models/view/fieldView.ts index f257cae7a5..0edcd796d5 100644 --- a/libs/common/src/models/view/fieldView.ts +++ b/libs/common/src/models/view/fieldView.ts @@ -26,7 +26,7 @@ export class FieldView implements View { return this.value != null ? "••••••••" : null; } - static fromJSON(obj: any): FieldView { + static fromJSON(obj: Partial): FieldView { const view = new FieldView(); view.name = obj.name; view.value = obj.value; diff --git a/libs/common/src/models/view/identityView.ts b/libs/common/src/models/view/identityView.ts index 284afcc06f..c033cfdfeb 100644 --- a/libs/common/src/models/view/identityView.ts +++ b/libs/common/src/models/view/identityView.ts @@ -140,7 +140,7 @@ export class IdentityView extends ItemView { return addressPart2; } - toJSON() { + toJSON(): Partial { // Needed to serialize getters which are not included by JSON.stringify return { title: this.title, @@ -164,7 +164,7 @@ export class IdentityView extends ItemView { }; } - static fromJSON(obj: any): IdentityView { + static fromJSON(obj: Partial): IdentityView { const view = new IdentityView(); view.title = obj.title; view.firstName = obj.firstName; diff --git a/libs/common/src/models/view/loginUriView.ts b/libs/common/src/models/view/loginUriView.ts index 9ad3adc785..6d5acff1c9 100644 --- a/libs/common/src/models/view/loginUriView.ts +++ b/libs/common/src/models/view/loginUriView.ts @@ -125,7 +125,7 @@ export class LoginUriView implements View { : this.uri; } - toJSON(): any { + toJSON(): Partial { // Needed to serialize getters which are not included by JSON.stringify return { match: this.match, @@ -133,7 +133,7 @@ export class LoginUriView implements View { }; } - static fromJSON(obj: any): LoginUriView { + static fromJSON(obj: Partial): LoginUriView { const view = new LoginUriView(); view.match = obj.match; view.uri = obj.uri; diff --git a/libs/common/src/models/view/loginView.ts b/libs/common/src/models/view/loginView.ts index 2d6a7ab8bd..78b4979ed1 100644 --- a/libs/common/src/models/view/loginView.ts +++ b/libs/common/src/models/view/loginView.ts @@ -61,7 +61,7 @@ export class LoginView extends ItemView { return this.uris != null && this.uris.length > 0; } - static fromJSON(obj: any): LoginView { + static fromJSON(obj: Partial): LoginView { const view = new LoginView(); view.username = obj.username; diff --git a/libs/common/src/models/view/passwordHistoryView.ts b/libs/common/src/models/view/passwordHistoryView.ts index a0f2a75f0f..3b2b788111 100644 --- a/libs/common/src/models/view/passwordHistoryView.ts +++ b/libs/common/src/models/view/passwordHistoryView.ts @@ -14,7 +14,7 @@ export class PasswordHistoryView implements View { this.lastUsedDate = ph.lastUsedDate; } - static fromJSON(obj: any): PasswordHistoryView { + static fromJSON(obj: Partial): PasswordHistoryView { const view = new PasswordHistoryView(); view.password = obj.password; view.lastUsedDate = obj.lastUsedDate == null ? null : new Date(obj.lastUsedDate); diff --git a/libs/common/src/models/view/secureNoteView.ts b/libs/common/src/models/view/secureNoteView.ts index d6e67c2a6d..fedfe1e879 100644 --- a/libs/common/src/models/view/secureNoteView.ts +++ b/libs/common/src/models/view/secureNoteView.ts @@ -19,7 +19,7 @@ export class SecureNoteView extends ItemView { return null; } - static fromJSON(obj: any): SecureNoteView { + static fromJSON(obj: Partial): SecureNoteView { const view = new SecureNoteView(); view.type = obj.type; return view;