From 4286234e6b9c4de9268a2de0cf98609d12d2a1f3 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Mon, 27 Nov 2023 15:56:43 +0100 Subject: [PATCH] MOBILE-3947 chore: Fix TS errors --- src/core/classes/database/database-table.ts | 2 +- src/core/classes/promise.ts | 2 +- src/core/features/course/services/course.ts | 4 ++-- .../features/course/services/format-delegate.ts | 2 +- src/core/features/courses/services/courses.ts | 5 ++++- src/core/services/file.ts | 3 ++- src/core/services/navigator.ts | 2 +- src/core/services/utils/utils.ts | 2 +- src/core/singletons/index.ts | 2 +- src/core/singletons/locutus.ts | 14 ++++++++------ src/core/singletons/object.ts | 10 +++++----- 11 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/core/classes/database/database-table.ts b/src/core/classes/database/database-table.ts index 629e95ed7..dc93ec1bc 100644 --- a/src/core/classes/database/database-table.ts +++ b/src/core/classes/database/database-table.ts @@ -125,7 +125,7 @@ export class CoreDatabaseTable< } const sorting = options?.sorting - && this.normalizedSorting(options.sorting).map(([column, direction]) => `${column} ${direction}`).join(', '); + && this.normalizedSorting(options.sorting).map(([column, direction]) => `${column.toString()} ${direction}`).join(', '); return this.database.getRecords(this.tableName, conditions, sorting, '*', options?.offset, options?.limit); } diff --git a/src/core/classes/promise.ts b/src/core/classes/promise.ts index 7fe5897b5..44564f834 100644 --- a/src/core/classes/promise.ts +++ b/src/core/classes/promise.ts @@ -23,7 +23,7 @@ export abstract class CorePromise implements Promise { this.nativePromise = nativePromise; } - [Symbol.toStringTag]: string; + [Symbol.toStringTag]!: string; /** * @inheritdoc diff --git a/src/core/features/course/services/course.ts b/src/core/features/course/services/course.ts index 9635f2cb1..7f05c23ae 100644 --- a/src/core/features/course/services/course.ts +++ b/src/core/features/course/services/course.ts @@ -238,11 +238,11 @@ export class CoreCourseProvider { } const course = await CoreCourses.getCourseByField('id', courseId, site.id); - const formatOptions = CoreUtils.objectToKeyValueMap<{ indentation?: string }>( + const formatOptions = CoreUtils.objectToKeyValueMap( course.courseformatoptions ?? [], 'name', 'value', - ); + ) as { indentation?: string }; return formatOptions.indentation === '1'; } diff --git a/src/core/features/course/services/format-delegate.ts b/src/core/features/course/services/format-delegate.ts index 643bd3a41..d19f9ccaf 100644 --- a/src/core/features/course/services/format-delegate.ts +++ b/src/core/features/course/services/format-delegate.ts @@ -275,7 +275,7 @@ export class CoreCourseFormatDelegateService extends CoreDelegate ({ navOptions, admOptions })), + map(([navOptions, admOptions]) => ({ + navOptions: navOptions as CoreCourseUserAdminOrNavOptionCourseIndexed, + admOptions: admOptions as CoreCourseUserAdminOrNavOptionCourseIndexed, + })), ); }); } diff --git a/src/core/services/file.ts b/src/core/services/file.ts index f5988f8b6..0fccddc04 100644 --- a/src/core/services/file.ts +++ b/src/core/services/file.ts @@ -933,7 +933,8 @@ export class CoreFileProvider { // If destFolder is not set, use same location as ZIP file. We need to use absolute paths (including basePath). destFolder = this.addBasePathIfNeeded(destFolder || CoreMimetypeUtils.removeExtension(path)); - const result = await Zip.unzip(fileEntry.toURL(), destFolder, onProgress); + // eslint-disable-next-line @typescript-eslint/ban-types + const result = await Zip.unzip(fileEntry.toURL(), destFolder, onProgress as unknown as Function); if (result == -1) { throw new CoreError('Unzip failed.'); diff --git a/src/core/services/navigator.ts b/src/core/services/navigator.ts index 2c164ce84..c94faf4ed 100644 --- a/src/core/services/navigator.ts +++ b/src/core/services/navigator.ts @@ -136,7 +136,7 @@ export class CoreNavigatorService { animated: options.animated, animation: options.animation, animationDirection: options.animationDirection, - queryParams: CoreObject.isEmpty(options.params ?? {}) ? null : CoreObject.withoutEmpty(options.params), + queryParams: CoreObject.isEmpty(options.params ?? {}) ? null : CoreObject.withoutEmpty(options.params ?? {}), relativeTo: path.startsWith('/') ? null : this.getCurrentRoute(), replaceUrl: options.replace, }); diff --git a/src/core/services/utils/utils.ts b/src/core/services/utils/utils.ts index b9710aaca..2e92b2973 100644 --- a/src/core/services/utils/utils.ts +++ b/src/core/services/utils/utils.ts @@ -1405,7 +1405,7 @@ export class CoreUtilsProvider { * @param enumeration Enumeration object. * @returns Keys of the enumeration. */ - enumKeys(enumeration: O): K[] { + enumKeys(enumeration: O): K[] { return Object.keys(enumeration).filter(k => Number.isNaN(+k)) as K[]; } diff --git a/src/core/singletons/index.ts b/src/core/singletons/index.ts index 52e8fea21..51df7f5f8 100644 --- a/src/core/singletons/index.ts +++ b/src/core/singletons/index.ts @@ -121,7 +121,7 @@ export function setCreateSingletonMethodProxy(method: typeof createSingletonMeth * defined using a class or the string used in the `provide` key if it was defined using an object. * @returns Singleton proxy. */ -export function makeSingleton( // eslint-disable-line @typescript-eslint/ban-types +export function makeSingleton( injectionToken: Type | AbstractType | Type | string, ): CoreSingletonProxy { const singleton = { diff --git a/src/core/singletons/locutus.ts b/src/core/singletons/locutus.ts index fd792ffd0..830cf8f95 100644 --- a/src/core/singletons/locutus.ts +++ b/src/core/singletons/locutus.ts @@ -66,7 +66,7 @@ function expectBool (str) { throw SyntaxError('Invalid bool value, expected 0 or 1') } - return [ boolMatch === '1', match.length ] + return [ boolMatch === '1', match?.length ] } function expectInt (str) { @@ -77,7 +77,7 @@ function expectInt (str) { throw SyntaxError('Expected an integer value') } - return [ parseInt(intMatch, 10), match.length ] + return [ parseInt(intMatch, 10), match?.length ] } function expectFloat (str) { @@ -105,7 +105,7 @@ function expectFloat (str) { break } - return [ floatValue, match.length ] + return [ floatValue, match?.length ] } function readBytes (str, len, escapedString = false) { @@ -260,7 +260,9 @@ function expectObject (str, cache) { str = str.substring(value[1]) totalOffset += value[1] - obj[prop[0]] = value[0] + if (prop[0]) { + obj[prop[0]] = value[0] + } } // strict parsing, expect } after object literal @@ -299,7 +301,7 @@ function expectArray (str, cache) { throw SyntaxError('Expected array length annotation') } - str = str.substring(arrayLiteralBeginMatch.length) + str = str.substring(arrayLiteralBeginMatch?.length) const array = expectArrayItems(str, parseInt(arrayLengthMatch, 10), cache) @@ -308,7 +310,7 @@ function expectArray (str, cache) { throw SyntaxError('Expected }') } - return [ array[0], arrayLiteralBeginMatch.length + (array[1] as number) + 1 ] // jump over } + return [ array[0], arrayLiteralBeginMatch?.length ?? 0 + (array[1] as number) + 1 ] // jump over } } function expectArrayItems (str, expectedItems = 0, cache) { diff --git a/src/core/singletons/object.ts b/src/core/singletons/object.ts index a0e0ee4ac..00e8dd65f 100644 --- a/src/core/singletons/object.ts +++ b/src/core/singletons/object.ts @@ -91,9 +91,9 @@ export class CoreObject { * @param keysOrRegex If array is supplied, keys to include. Otherwise, regular expression used to filter keys. * @returns New object with only the specified keys. */ - static only(obj: T, keys: K[]): Pick; - static only(obj: T, regex: RegExp): Partial; - static only(obj: T, keysOrRegex: K[] | RegExp): Pick | Partial { + static only(obj: T, keys: K[]): Pick; + static only(obj: T, regex: RegExp): Partial; + static only(obj: T, keysOrRegex: K[] | RegExp): Pick | Partial { const newObject: Partial = {}; if (Array.isArray(keysOrRegex)) { @@ -136,7 +136,7 @@ export class CoreObject { * @param obj Objet. * @returns New object without empty values. */ - static withoutEmpty(obj: T): CoreObjectWithoutEmpty { + static withoutEmpty(obj: T): CoreObjectWithoutEmpty { const cleanObj = {}; for (const [key, value] of Object.entries(obj)) { @@ -156,7 +156,7 @@ export class CoreObject { * @param obj Objet. * @returns New object without undefined values. */ - static withoutUndefined(obj: T): CoreObjectWithoutUndefined { + static withoutUndefined(obj: T): CoreObjectWithoutUndefined { const cleanObj = {}; for (const [key, value] of Object.entries(obj)) {