diff --git a/package.json b/package.json index c3b30fb64..ac7a47d68 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "rxjs": "^7.5.7", "serve": "^14.1.1", "ts-jest": "^29.0.3", - "typescript": "^4.8.4" + "typescript": "^4.9.3" }, "packageManager": "pnpm@7.15.0", "engines": { diff --git a/packages/common/src/formatters/formatterUtilities.ts b/packages/common/src/formatters/formatterUtilities.ts index 2177d141f..9cc14defb 100644 --- a/packages/common/src/formatters/formatterUtilities.ts +++ b/packages/common/src/formatters/formatterUtilities.ts @@ -139,7 +139,7 @@ export function parseFormatterWhenExist(formatter: Formatter | undef fieldProperty = (props.length > 0) ? props[0] : columnDef.field; } - const cellValue = (dataContext as any).hasOwnProperty(fieldProperty) ? (dataContext as any)[fieldProperty] : null; + const cellValue = dataContext?.hasOwnProperty(fieldProperty as keyof T) ? dataContext[fieldProperty as keyof T] : null; if (typeof formatter === 'function') { const formattedData = formatter(row, col, cellValue, columnDef, dataContext, grid); @@ -151,7 +151,7 @@ export function parseFormatterWhenExist(formatter: Formatter | undef output = ''; } } else { - output = (!(dataContext as any).hasOwnProperty(fieldProperty)) ? '' : cellValue; + output = ((!dataContext?.hasOwnProperty(fieldProperty as keyof T)) ? '' : cellValue) as string; if (output === null || output === undefined) { output = ''; } diff --git a/packages/common/src/services/collection.service.ts b/packages/common/src/services/collection.service.ts index d1f8b091c..3df153504 100644 --- a/packages/common/src/services/collection.service.ts +++ b/packages/common/src/services/collection.service.ts @@ -59,21 +59,21 @@ export class CollectionService { switch (operator) { case OperatorType.equal: if (objectProperty) { - filteredCollection = collection.filter((item) => (item as any)[objectProperty] === value); + filteredCollection = collection.filter((item) => item[objectProperty as keyof T] === value); } else { filteredCollection = collection.filter((item) => item === value); } break; case OperatorType.contains: if (objectProperty) { - filteredCollection = collection.filter((item) => (item as any)[objectProperty].toString().indexOf(value.toString()) !== -1); + filteredCollection = collection.filter((item) => item[objectProperty as keyof T]?.toString().indexOf(value.toString()) !== -1); } else { filteredCollection = collection.filter((item: any) => (item !== null && item !== undefined) && item.toString().indexOf(value.toString()) !== -1); } break; case OperatorType.notContains: if (objectProperty) { - filteredCollection = collection.filter((item) => (item as any)[objectProperty].toString().indexOf(value.toString()) === -1); + filteredCollection = collection.filter((item) => item[objectProperty as keyof T]?.toString().indexOf(value.toString()) === -1); } else { filteredCollection = collection.filter((item: any) => (item !== null && item !== undefined) && item.toString().indexOf(value.toString()) === -1); } @@ -81,7 +81,7 @@ export class CollectionService { case OperatorType.notEqual: default: if (objectProperty) { - filteredCollection = collection.filter((item) => (item as any)[objectProperty] !== value); + filteredCollection = collection.filter((item) => item[objectProperty as keyof T] !== value); } else { filteredCollection = collection.filter((item) => item !== value); } @@ -116,8 +116,8 @@ export class CollectionService { const sortDirection = sortBy.sortDesc ? SortDirectionNumber.desc : SortDirectionNumber.asc; const objectProperty = sortBy.property; const fieldType = sortBy?.fieldType ?? columnDef?.type ?? FieldType.string; - const value1 = (enableTranslateLabel) ? this.translaterService?.translate && this.translaterService.translate((dataRow1 as any)[objectProperty] || ' ') : (dataRow1 as any)[objectProperty]; - const value2 = (enableTranslateLabel) ? this.translaterService?.translate && this.translaterService.translate((dataRow2 as any)[objectProperty] || ' ') : (dataRow2 as any)[objectProperty]; + const value1 = (enableTranslateLabel) ? this.translaterService?.translate && this.translaterService.translate((dataRow1[objectProperty as keyof T] || ' ') as string) : dataRow1[objectProperty as keyof T]; + const value2 = (enableTranslateLabel) ? this.translaterService?.translate && this.translaterService.translate((dataRow2[objectProperty as keyof T] || ' ') as string) : dataRow2[objectProperty as keyof T]; const sortResult = sortByFieldType(fieldType, value1, value2, sortDirection, columnDef); if (sortResult !== SortDirectionNumber.neutral) { @@ -135,8 +135,8 @@ export class CollectionService { const fieldType = sortByOptions?.fieldType ?? columnDef?.type ?? FieldType.string; sortedCollection = collection.sort((dataRow1: T, dataRow2: T) => { - const value1 = (enableTranslateLabel) ? this.translaterService?.translate && this.translaterService.translate((dataRow1 as any)[objectProperty] || ' ') : (dataRow1 as any)[objectProperty]; - const value2 = (enableTranslateLabel) ? this.translaterService?.translate && this.translaterService.translate((dataRow2 as any)[objectProperty] || ' ') : (dataRow2 as any)[objectProperty]; + const value1 = (enableTranslateLabel) ? this.translaterService?.translate && this.translaterService.translate((dataRow1[objectProperty as keyof T] || ' ') as string) : dataRow1[objectProperty as keyof T]; + const value2 = (enableTranslateLabel) ? this.translaterService?.translate && this.translaterService.translate((dataRow2[objectProperty as keyof T] || ' ') as string) : dataRow2[objectProperty as keyof T]; const sortResult = sortByFieldType(fieldType, value1, value2, sortDirection, columnDef); if (sortResult !== SortDirectionNumber.neutral) { return sortResult; diff --git a/packages/common/src/services/grid.service.ts b/packages/common/src/services/grid.service.ts index 9cbd06d69..7d1eef516 100644 --- a/packages/common/src/services/grid.service.ts +++ b/packages/common/src/services/grid.service.ts @@ -402,7 +402,7 @@ export class GridService { throw new Error('We could not find SlickGrid Grid, DataView objects'); } const idPropName = this._gridOptions.datasetIdPropertyName || 'id'; - if (!options?.skipError && (!item || !(idPropName in item))) { + if (!options?.skipError && (!item || !item.hasOwnProperty(idPropName))) { throw new Error(`Adding an item requires the item to include an "${idPropName}" property`); } @@ -506,7 +506,7 @@ export class GridService { // get row numbers of all new inserted items // we need to do it after resort and get each row number because it possibly changed after the sort - items.forEach((item: T) => rowNumbers.push(this._dataView.getRowById((item as any)[idPropName]) as number)); + items.forEach((item: T) => rowNumbers.push(this._dataView.getRowById(item[idPropName as keyof T] as string | number) as number)); // if user wanted to see highlighted row if (options.highlightRow) { @@ -536,10 +536,10 @@ export class GridService { options = { ...GridServiceDeleteOptionDefaults, ...options }; const idPropName = this._gridOptions.datasetIdPropertyName || 'id'; - if (!options?.skipError && (!item || !(idPropName in item))) { + if (!options?.skipError && (!item || !item.hasOwnProperty(idPropName))) { throw new Error(`Deleting an item requires the item to include an "${idPropName}" property`); } - return this.deleteItemById((item as any)[idPropName], options); + return this.deleteItemById(item[idPropName as keyof T] as string | number, options); } /** @@ -650,7 +650,7 @@ export class GridService { updateItem(item: T, options?: GridServiceUpdateOption): number | undefined { options = { ...GridServiceUpdateOptionDefaults, ...options }; const idPropName = this._gridOptions.datasetIdPropertyName || 'id'; - const itemId = (!item || !(idPropName in item)) ? undefined : (item as any)[idPropName]; + const itemId = (!item || !item.hasOwnProperty(idPropName)) ? undefined : (item as any)[idPropName]; if (!options?.skipError && itemId === undefined) { throw new Error(`Calling Update of an item requires the item to include an "${idPropName}" property`); @@ -682,7 +682,7 @@ export class GridService { const rowNumbers: number[] = []; const itemIds: Array = []; items.forEach((item: T) => { - const itemId = (!item || !(idPropName in item)) ? undefined : (item as any)[idPropName]; + const itemId = (!item || !item.hasOwnProperty(idPropName)) ? undefined : (item as any)[idPropName]; itemIds.push(itemId); if (this._dataView.getIdxById(itemId) !== undefined) { @@ -786,7 +786,7 @@ export class GridService { upsertItem(item: T, options?: GridServiceInsertOption): { added: number | undefined; updated: number | undefined; } { options = { ...GridServiceInsertOptionDefaults, ...options }; const idPropName = this._gridOptions.datasetIdPropertyName || 'id'; - const itemId = (!item || !(idPropName in item)) ? undefined : (item as any)[idPropName]; + const itemId = (!item || !item.hasOwnProperty(idPropName)) ? undefined : (item as any)[idPropName]; if (!options?.skipError && itemId === undefined) { throw new Error(`Calling Upsert of an item requires the item to include an "${idPropName}" property`); diff --git a/packages/common/src/services/utilities.ts b/packages/common/src/services/utilities.ts index 6fe87b99b..e0930418b 100644 --- a/packages/common/src/services/utilities.ts +++ b/packages/common/src/services/utilities.ts @@ -173,13 +173,13 @@ export function findItemInTreeStructure(treeArray: T[], predicate: (ite throw new Error('findRecursive requires parameter "childrenPropertyName"'); } const initialFind = treeArray.find(predicate); - const elementsWithChildren = treeArray.filter((x: T) => childrenPropertyName in x && (x as any)[childrenPropertyName]); + const elementsWithChildren = treeArray.filter((x: T) => x?.hasOwnProperty(childrenPropertyName) && x[childrenPropertyName as keyof T]); if (initialFind) { return initialFind; } else if (elementsWithChildren.length) { const childElements: T[] = []; elementsWithChildren.forEach((item: T) => { - if (childrenPropertyName in item) { + if (item?.hasOwnProperty(childrenPropertyName)) { childElements.push(...(item as any)[childrenPropertyName]); } }); diff --git a/packages/utils/src/utils.ts b/packages/utils/src/utils.ts index 06289ea96..b15ee06de 100644 --- a/packages/utils/src/utils.ts +++ b/packages/utils/src/utils.ts @@ -7,7 +7,7 @@ export function addToArrayWhenNotExists(inputArray: T[], inputItem: T, itemIdPropName = 'id') { let arrayRowIndex = -1; if (inputItem && typeof inputItem === 'object' && itemIdPropName in inputItem) { - arrayRowIndex = inputArray.findIndex((item) => (item as any)[itemIdPropName] === (inputItem as any)[itemIdPropName]); + arrayRowIndex = inputArray.findIndex((item) => item[itemIdPropName as keyof T] === inputItem[itemIdPropName as keyof T]); } else { arrayRowIndex = inputArray.findIndex((item) => item === inputItem); } diff --git a/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts b/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts index 777d1b997..8587f5bb9 100644 --- a/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts +++ b/packages/vanilla-bundle/src/components/slick-vanilla-grid-bundle.ts @@ -448,7 +448,7 @@ export class SlickVanillaGridBundle { if (this.backendServiceApi) { for (const prop of Object.keys(this.backendServiceApi)) { - (this.backendServiceApi as any)[prop] = null; + this.backendServiceApi[prop as keyof BackendServiceApi] = null; } this.backendServiceApi = undefined; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7883b3739..8ab05a752 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,7 +29,7 @@ importers: rxjs: ^7.5.7 serve: ^14.1.1 ts-jest: ^29.0.3 - typescript: ^4.8.4 + typescript: ^4.9.3 devDependencies: '@4tw/cypress-drag-drop': 2.2.1_cypress@11.0.1 '@jest/types': 29.3.1 @@ -37,8 +37,8 @@ importers: '@lerna-lite/run': 1.12.0 '@types/jest': 29.2.2 '@types/node': 18.11.9 - '@typescript-eslint/eslint-plugin': 5.42.1_2udltptbznfmezdozpdoa2aemq - '@typescript-eslint/parser': 5.42.1_rmayb2veg2btbq6mbmnyivgasy + '@typescript-eslint/eslint-plugin': 5.42.1_a76fwnskzo2n3ynumjbqxmyj7i + '@typescript-eslint/parser': 5.42.1_e3uo4sehh4zr4i6m57mkkxxv7y cross-env: 7.0.3 cypress: 11.0.1 eslint: 8.27.0 @@ -55,8 +55,8 @@ importers: rimraf: 3.0.2 rxjs: 7.5.7 serve: 14.1.1 - ts-jest: 29.0.3_vkkdur4cjg6zp2tpwxfzdfg5su - typescript: 4.8.4 + ts-jest: 29.0.3_wcjxlcwfjvs73rqh2tjbxyoefa + typescript: 4.9.3 examples/webpack-demo-vanilla-bundle: specifiers: @@ -2129,7 +2129,7 @@ packages: dev: true optional: true - /@typescript-eslint/eslint-plugin/5.42.1_2udltptbznfmezdozpdoa2aemq: + /@typescript-eslint/eslint-plugin/5.42.1_a76fwnskzo2n3ynumjbqxmyj7i: resolution: {integrity: sha512-LyR6x784JCiJ1j6sH5Y0K6cdExqCCm8DJUTcwG5ThNXJj/G8o5E56u5EdG4SLy+bZAwZBswC+GYn3eGdttBVCg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -2140,23 +2140,23 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/parser': 5.42.1_rmayb2veg2btbq6mbmnyivgasy + '@typescript-eslint/parser': 5.42.1_e3uo4sehh4zr4i6m57mkkxxv7y '@typescript-eslint/scope-manager': 5.42.1 - '@typescript-eslint/type-utils': 5.42.1_rmayb2veg2btbq6mbmnyivgasy - '@typescript-eslint/utils': 5.42.1_rmayb2veg2btbq6mbmnyivgasy + '@typescript-eslint/type-utils': 5.42.1_e3uo4sehh4zr4i6m57mkkxxv7y + '@typescript-eslint/utils': 5.42.1_e3uo4sehh4zr4i6m57mkkxxv7y debug: 4.3.4 eslint: 8.27.0 ignore: 5.2.0 natural-compare-lite: 1.4.0 regexpp: 3.2.0 semver: 7.3.8 - tsutils: 3.21.0_typescript@4.8.4 - typescript: 4.8.4 + tsutils: 3.21.0_typescript@4.9.3 + typescript: 4.9.3 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/parser/5.42.1_rmayb2veg2btbq6mbmnyivgasy: + /@typescript-eslint/parser/5.42.1_e3uo4sehh4zr4i6m57mkkxxv7y: resolution: {integrity: sha512-kAV+NiNBWVQDY9gDJDToTE/NO8BHi4f6b7zTsVAJoTkmB/zlfOpiEVBzHOKtlgTndCKe8vj9F/PuolemZSh50Q==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -2168,10 +2168,10 @@ packages: dependencies: '@typescript-eslint/scope-manager': 5.42.1 '@typescript-eslint/types': 5.42.1 - '@typescript-eslint/typescript-estree': 5.42.1_typescript@4.8.4 + '@typescript-eslint/typescript-estree': 5.42.1_typescript@4.9.3 debug: 4.3.4 eslint: 8.27.0 - typescript: 4.8.4 + typescript: 4.9.3 transitivePeerDependencies: - supports-color dev: true @@ -2184,7 +2184,7 @@ packages: '@typescript-eslint/visitor-keys': 5.42.1 dev: true - /@typescript-eslint/type-utils/5.42.1_rmayb2veg2btbq6mbmnyivgasy: + /@typescript-eslint/type-utils/5.42.1_e3uo4sehh4zr4i6m57mkkxxv7y: resolution: {integrity: sha512-WWiMChneex5w4xPIX56SSnQQo0tEOy5ZV2dqmj8Z371LJ0E+aymWD25JQ/l4FOuuX+Q49A7pzh/CGIQflxMVXg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -2194,12 +2194,12 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/typescript-estree': 5.42.1_typescript@4.8.4 - '@typescript-eslint/utils': 5.42.1_rmayb2veg2btbq6mbmnyivgasy + '@typescript-eslint/typescript-estree': 5.42.1_typescript@4.9.3 + '@typescript-eslint/utils': 5.42.1_e3uo4sehh4zr4i6m57mkkxxv7y debug: 4.3.4 eslint: 8.27.0 - tsutils: 3.21.0_typescript@4.8.4 - typescript: 4.8.4 + tsutils: 3.21.0_typescript@4.9.3 + typescript: 4.9.3 transitivePeerDependencies: - supports-color dev: true @@ -2209,7 +2209,7 @@ packages: engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true - /@typescript-eslint/typescript-estree/5.42.1_typescript@4.8.4: + /@typescript-eslint/typescript-estree/5.42.1_typescript@4.9.3: resolution: {integrity: sha512-qElc0bDOuO0B8wDhhW4mYVgi/LZL+igPwXtV87n69/kYC/7NG3MES0jHxJNCr4EP7kY1XVsRy8C/u3DYeTKQmw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -2224,13 +2224,13 @@ packages: globby: 11.1.0 is-glob: 4.0.3 semver: 7.3.8 - tsutils: 3.21.0_typescript@4.8.4 - typescript: 4.8.4 + tsutils: 3.21.0_typescript@4.9.3 + typescript: 4.9.3 transitivePeerDependencies: - supports-color dev: true - /@typescript-eslint/utils/5.42.1_rmayb2veg2btbq6mbmnyivgasy: + /@typescript-eslint/utils/5.42.1_e3uo4sehh4zr4i6m57mkkxxv7y: resolution: {integrity: sha512-Gxvf12xSp3iYZd/fLqiQRD4uKZjDNR01bQ+j8zvhPjpsZ4HmvEFL/tC4amGNyxN9Rq+iqvpHLhlqx6KTxz9ZyQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -2240,7 +2240,7 @@ packages: '@types/semver': 7.3.12 '@typescript-eslint/scope-manager': 5.42.1 '@typescript-eslint/types': 5.42.1 - '@typescript-eslint/typescript-estree': 5.42.1_typescript@4.8.4 + '@typescript-eslint/typescript-estree': 5.42.1_typescript@4.9.3 eslint: 8.27.0 eslint-scope: 5.1.1 eslint-utils: 3.0.0_eslint@8.27.0 @@ -4616,7 +4616,7 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: - '@typescript-eslint/parser': 5.42.1_rmayb2veg2btbq6mbmnyivgasy + '@typescript-eslint/parser': 5.42.1_e3uo4sehh4zr4i6m57mkkxxv7y debug: 3.2.7 eslint-import-resolver-node: 0.3.6 find-up: 2.1.0 @@ -4634,7 +4634,7 @@ packages: '@typescript-eslint/parser': optional: true dependencies: - '@typescript-eslint/parser': 5.42.1_rmayb2veg2btbq6mbmnyivgasy + '@typescript-eslint/parser': 5.42.1_e3uo4sehh4zr4i6m57mkkxxv7y array-includes: 3.1.5 array.prototype.flat: 1.3.0 debug: 2.6.9 @@ -9855,7 +9855,7 @@ packages: engines: {node: '>=8'} dev: true - /ts-jest/29.0.3_vkkdur4cjg6zp2tpwxfzdfg5su: + /ts-jest/29.0.3_wcjxlcwfjvs73rqh2tjbxyoefa: resolution: {integrity: sha512-Ibygvmuyq1qp/z3yTh9QTwVVAbFdDy/+4BtIQR2sp6baF2SJU/8CKK/hhnGIDY2L90Az2jIqTwZPnN2p+BweiQ==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} hasBin: true @@ -9885,7 +9885,7 @@ packages: lodash.memoize: 4.1.2 make-error: 1.3.6 semver: 7.3.7 - typescript: 4.8.4 + typescript: 4.9.3 yargs-parser: 21.0.1 dev: true @@ -9905,14 +9905,14 @@ packages: /tslib/2.4.0: resolution: {integrity: sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==} - /tsutils/3.21.0_typescript@4.8.4: + /tsutils/3.21.0_typescript@4.9.3: resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} engines: {node: '>= 6'} peerDependencies: typescript: '>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta' dependencies: tslib: 1.14.1 - typescript: 4.8.4 + typescript: 4.9.3 dev: true /tunnel-agent/0.6.0: @@ -10003,6 +10003,12 @@ packages: hasBin: true dev: true + /typescript/4.9.3: + resolution: {integrity: sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==} + engines: {node: '>=4.2.0'} + hasBin: true + dev: true + /uglify-js/3.16.2: resolution: {integrity: sha512-AaQNokTNgExWrkEYA24BTNMSjyqEXPSfhqoS0AxmHkCJ4U+Dyy5AvbGV/sqxuxficEfGGoX3zWw9R7QpLFfEsg==} engines: {node: '>=0.8.0'}