Browse Source

fix(core): Fix TypeScript errors arising in v3.5.1

Michael Bromley 6 years ago
parent
commit
8e78450d0f

+ 2 - 2
packages/common/src/simple-deep-clone.ts

@@ -2,7 +2,7 @@
  * An extremely fast function for deep-cloning an object which only contains simple
  * values, i.e. primitives, arrays and nested simple objects.
  */
-export function simpleDeepClone<T>(input: T): T {
+export function simpleDeepClone<T extends string | number | any[] | object>(input: T): T {
     // if not array or object or is null return self
     if (typeof input !== 'object' || input === null) {
         return input;
@@ -21,7 +21,7 @@ export function simpleDeepClone<T>(input: T): T {
     // handle case: object
     output = {};
     for (i in input) {
-        if (input.hasOwnProperty(i)) {
+        if ((input).hasOwnProperty(i)) {
             output[i] = simpleDeepClone((input as any)[i]);
         }
     }

+ 2 - 1
packages/core/src/api/middleware/translate-errors-extension.ts

@@ -1,4 +1,5 @@
 import { Response } from 'express-serve-static-core';
+import { GraphQLError } from 'graphql';
 import { GraphQLExtension, GraphQLResponse } from 'graphql-extensions';
 
 import { I18nRequest, I18nService } from '../../i18n/i18n.service';
@@ -20,7 +21,7 @@ export class TranslateErrorExtension implements GraphQLExtension {
         const { graphqlResponse, context } = o;
         if (graphqlResponse.errors) {
             graphqlResponse.errors = graphqlResponse.errors.map(err => {
-                return this.i18nService.translateError(context.req, err) as any;
+                return this.i18nService.translateError(context.req, err as GraphQLError) as any;
             });
         }
         return o;

+ 2 - 2
packages/core/src/common/configurable-operation.ts

@@ -60,10 +60,10 @@ export function configurableDefToOperation(def: ConfigurableOperationDef): Confi
  * { foo: 'bar' }
  **/
 export function argsArrayToHash<T>(args: ConfigArg[]): ConfigArgValues<T> {
-    const output: ConfigArgValues<T> & { [key: string]: any } = {} as any;
+    const output: ConfigArgValues<T> = {} as any;
     for (const arg of args) {
         if (arg.value != null) {
-            output[arg.name] = coerceValueToType<T>(arg);
+            output[arg.name as keyof ConfigArgValues<T>] = coerceValueToType<T>(arg);
         }
     }
     return output;

+ 1 - 1
packages/core/src/service/helpers/list-query-builder/parse-filter-params.ts

@@ -47,7 +47,7 @@ export function parseFilterParams<T extends VendureEntity>(
 
     for (const [key, operation] of Object.entries(filterParams)) {
         if (operation) {
-            for (const [operator, operand] of Object.entries(operation)) {
+            for (const [operator, operand] of Object.entries(operation as object)) {
                 let fieldName: string;
                 if (columns.find(c => c.propertyName === key)) {
                     fieldName = `${alias}.${key}`;

+ 2 - 2
packages/core/src/service/helpers/list-query-builder/parse-sort-params.ts

@@ -39,9 +39,9 @@ export function parseSortParams<T extends VendureEntity>(
 
     for (const [key, order] of Object.entries(sortParams)) {
         if (columns.find(c => c.propertyName === key)) {
-            output[`${alias}.${key}`] = order;
+            output[`${alias}.${key}`] = order as any;
         } else if (translationColumns.find(c => c.propertyName === key)) {
-            output[`${alias}_translations.${key}`] = order;
+            output[`${alias}_translations.${key}`] = order as any;
         } else {
             throw new UserInputError('error.invalid-sort-field', {
                 fieldName: key,