MOBILE-3947 chore: Fix TS errors

main
Noel De Martin 2023-11-27 15:56:43 +01:00
parent af215a7f5c
commit 4286234e6b
11 changed files with 27 additions and 21 deletions

View File

@ -125,7 +125,7 @@ export class CoreDatabaseTable<
} }
const sorting = options?.sorting 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); return this.database.getRecords(this.tableName, conditions, sorting, '*', options?.offset, options?.limit);
} }

View File

@ -23,7 +23,7 @@ export abstract class CorePromise<T = unknown> implements Promise<T> {
this.nativePromise = nativePromise; this.nativePromise = nativePromise;
} }
[Symbol.toStringTag]: string; [Symbol.toStringTag]!: string;
/** /**
* @inheritdoc * @inheritdoc

View File

@ -238,11 +238,11 @@ export class CoreCourseProvider {
} }
const course = await CoreCourses.getCourseByField('id', courseId, site.id); const course = await CoreCourses.getCourseByField('id', courseId, site.id);
const formatOptions = CoreUtils.objectToKeyValueMap<{ indentation?: string }>( const formatOptions = CoreUtils.objectToKeyValueMap(
course.courseformatoptions ?? [], course.courseformatoptions ?? [],
'name', 'name',
'value', 'value',
); ) as { indentation?: string };
return formatOptions.indentation === '1'; return formatOptions.indentation === '1';
} }

View File

@ -275,7 +275,7 @@ export class CoreCourseFormatDelegateService extends CoreDelegate<CoreCourseForm
[course, sections], [course, sections],
); );
if (sectionData && 'forceSelected' in sectionData) { if (sectionData && typeof sectionData === 'object' && 'forceSelected' in sectionData) {
return sectionData; return sectionData;
} else if (sectionData) { } else if (sectionData) {
// Function just returned the section, don't force selecting it. // Function just returned the section, don't force selecting it.

View File

@ -636,7 +636,10 @@ export class CoreCoursesProvider {
ignoreErrors(this.getUserNavigationOptionsObservable(courseIds, options), {}), ignoreErrors(this.getUserNavigationOptionsObservable(courseIds, options), {}),
ignoreErrors(this.getUserAdministrationOptionsObservable(courseIds, options), {}), ignoreErrors(this.getUserAdministrationOptionsObservable(courseIds, options), {}),
).pipe( ).pipe(
map(([navOptions, admOptions]) => ({ navOptions, admOptions })), map(([navOptions, admOptions]) => ({
navOptions: navOptions as CoreCourseUserAdminOrNavOptionCourseIndexed,
admOptions: admOptions as CoreCourseUserAdminOrNavOptionCourseIndexed,
})),
); );
}); });
} }

View File

@ -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). // 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)); 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) { if (result == -1) {
throw new CoreError('Unzip failed.'); throw new CoreError('Unzip failed.');

View File

@ -136,7 +136,7 @@ export class CoreNavigatorService {
animated: options.animated, animated: options.animated,
animation: options.animation, animation: options.animation,
animationDirection: options.animationDirection, 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(), relativeTo: path.startsWith('/') ? null : this.getCurrentRoute(),
replaceUrl: options.replace, replaceUrl: options.replace,
}); });

View File

@ -1405,7 +1405,7 @@ export class CoreUtilsProvider {
* @param enumeration Enumeration object. * @param enumeration Enumeration object.
* @returns Keys of the enumeration. * @returns Keys of the enumeration.
*/ */
enumKeys<O, K extends keyof O = keyof O>(enumeration: O): K[] { enumKeys<O extends object, K extends keyof O = keyof O>(enumeration: O): K[] {
return Object.keys(enumeration).filter(k => Number.isNaN(+k)) as K[]; return Object.keys(enumeration).filter(k => Number.isNaN(+k)) as K[];
} }

View File

@ -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. * defined using a class or the string used in the `provide` key if it was defined using an object.
* @returns Singleton proxy. * @returns Singleton proxy.
*/ */
export function makeSingleton<Service extends object = object>( // eslint-disable-line @typescript-eslint/ban-types export function makeSingleton<Service extends object = object>(
injectionToken: Type<Service> | AbstractType<Service> | Type<unknown> | string, injectionToken: Type<Service> | AbstractType<Service> | Type<unknown> | string,
): CoreSingletonProxy<Service> { ): CoreSingletonProxy<Service> {
const singleton = { const singleton = {

View File

@ -66,7 +66,7 @@ function expectBool (str) {
throw SyntaxError('Invalid bool value, expected 0 or 1') throw SyntaxError('Invalid bool value, expected 0 or 1')
} }
return [ boolMatch === '1', match.length ] return [ boolMatch === '1', match?.length ]
} }
function expectInt (str) { function expectInt (str) {
@ -77,7 +77,7 @@ function expectInt (str) {
throw SyntaxError('Expected an integer value') throw SyntaxError('Expected an integer value')
} }
return [ parseInt(intMatch, 10), match.length ] return [ parseInt(intMatch, 10), match?.length ]
} }
function expectFloat (str) { function expectFloat (str) {
@ -105,7 +105,7 @@ function expectFloat (str) {
break break
} }
return [ floatValue, match.length ] return [ floatValue, match?.length ]
} }
function readBytes (str, len, escapedString = false) { function readBytes (str, len, escapedString = false) {
@ -260,7 +260,9 @@ function expectObject (str, cache) {
str = str.substring(value[1]) str = str.substring(value[1])
totalOffset += value[1] totalOffset += value[1]
obj[prop[0]] = value[0] if (prop[0]) {
obj[prop[0]] = value[0]
}
} }
// strict parsing, expect } after object literal // strict parsing, expect } after object literal
@ -299,7 +301,7 @@ function expectArray (str, cache) {
throw SyntaxError('Expected array length annotation') throw SyntaxError('Expected array length annotation')
} }
str = str.substring(arrayLiteralBeginMatch.length) str = str.substring(arrayLiteralBeginMatch?.length)
const array = expectArrayItems(str, parseInt(arrayLengthMatch, 10), cache) const array = expectArrayItems(str, parseInt(arrayLengthMatch, 10), cache)
@ -308,7 +310,7 @@ function expectArray (str, cache) {
throw SyntaxError('Expected }') 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) { function expectArrayItems (str, expectedItems = 0, cache) {

View File

@ -91,9 +91,9 @@ export class CoreObject {
* @param keysOrRegex If array is supplied, keys to include. Otherwise, regular expression used to filter keys. * @param keysOrRegex If array is supplied, keys to include. Otherwise, regular expression used to filter keys.
* @returns New object with only the specified keys. * @returns New object with only the specified keys.
*/ */
static only<T, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>; static only<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
static only<T>(obj: T, regex: RegExp): Partial<T>; static only<T extends object>(obj: T, regex: RegExp): Partial<T>;
static only<T, K extends keyof T>(obj: T, keysOrRegex: K[] | RegExp): Pick<T, K> | Partial<T> { static only<T extends object, K extends keyof T>(obj: T, keysOrRegex: K[] | RegExp): Pick<T, K> | Partial<T> {
const newObject: Partial<T> = {}; const newObject: Partial<T> = {};
if (Array.isArray(keysOrRegex)) { if (Array.isArray(keysOrRegex)) {
@ -136,7 +136,7 @@ export class CoreObject {
* @param obj Objet. * @param obj Objet.
* @returns New object without empty values. * @returns New object without empty values.
*/ */
static withoutEmpty<T>(obj: T): CoreObjectWithoutEmpty<T> { static withoutEmpty<T extends object>(obj: T): CoreObjectWithoutEmpty<T> {
const cleanObj = {}; const cleanObj = {};
for (const [key, value] of Object.entries(obj)) { for (const [key, value] of Object.entries(obj)) {
@ -156,7 +156,7 @@ export class CoreObject {
* @param obj Objet. * @param obj Objet.
* @returns New object without undefined values. * @returns New object without undefined values.
*/ */
static withoutUndefined<T>(obj: T): CoreObjectWithoutUndefined<T> { static withoutUndefined<T extends object>(obj: T): CoreObjectWithoutUndefined<T> {
const cleanObj = {}; const cleanObj = {};
for (const [key, value] of Object.entries(obj)) { for (const [key, value] of Object.entries(obj)) {