From dec78da67c92750aae30805adc13b9a2e90d4d61 Mon Sep 17 00:00:00 2001 From: Van Nguyen <36019388+nguyentvan7@users.noreply.github.com> Date: Tue, 2 Jan 2024 12:10:41 -0700 Subject: [PATCH] Tidy tsconfig and add object-overrides global type --- apps/sr-frontend/tsconfig.app.json | 2 +- libs/pando/tsconfig.lib.json | 2 +- libs/sr-db/src/Database/DataManager.ts | 10 ++++------ libs/sr-db/tsconfig.lib.json | 2 +- libs/sr-formula/tsconfig.lib.json | 2 +- libs/sr-srod/package.json | 5 +++++ libs/sr-srod/project.json | 6 ++++++ tsconfig.base.json | 1 + types/object-overrides/index.d.ts | 22 ++++++++++++++++++++++ 9 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 libs/sr-srod/package.json create mode 100644 types/object-overrides/index.d.ts diff --git a/apps/sr-frontend/tsconfig.app.json b/apps/sr-frontend/tsconfig.app.json index 49d245b8de..37e8b57668 100644 --- a/apps/sr-frontend/tsconfig.app.json +++ b/apps/sr-frontend/tsconfig.app.json @@ -2,7 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "outDir": "../../dist/out-tsc", - "types": ["node", "vite/client"] + "types": ["node", "vite/client", "object-overrides"] }, "exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"], "include": ["src/**/*.ts", "src/**/*.tsx"] diff --git a/libs/pando/tsconfig.lib.json b/libs/pando/tsconfig.lib.json index 629099ac91..3f5f337abc 100644 --- a/libs/pando/tsconfig.lib.json +++ b/libs/pando/tsconfig.lib.json @@ -2,7 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "outDir": "../../dist/out-tsc", - "types": ["node", "vite/client"] + "types": ["node"] }, "include": ["src/**/*.ts"], "exclude": ["**/*.spec.ts", "vitest.config.ts"] diff --git a/libs/sr-db/src/Database/DataManager.ts b/libs/sr-db/src/Database/DataManager.ts index cd2f85b683..509bc23ea1 100644 --- a/libs/sr-db/src/Database/DataManager.ts +++ b/libs/sr-db/src/Database/DataManager.ts @@ -18,12 +18,10 @@ export class DataManager< > { exportSROD(sro: Partial) { const key = this.dataKey.replace('sro_', '') - sro[key] = (Object.entries(this.data) as [CacheKey, CacheValue][]).map( - ([id, value]) => ({ - ...this.deCache(value), - id, - }) - ) + sro[key] = Object.entries(this.data).map(([id, value]) => ({ + ...this.deCache(value), + id, + })) } importSROD(sro: ISrObjectDescription & ISroDatabase, _result: ImportResult) { const entries = sro[this.dataKey] diff --git a/libs/sr-db/tsconfig.lib.json b/libs/sr-db/tsconfig.lib.json index 33eca2c2cd..3e3e2d9ba2 100644 --- a/libs/sr-db/tsconfig.lib.json +++ b/libs/sr-db/tsconfig.lib.json @@ -3,7 +3,7 @@ "compilerOptions": { "outDir": "../../dist/out-tsc", "declaration": true, - "types": ["node"] + "types": ["node", "object-overrides"] }, "include": ["src/**/*.ts"], "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"] diff --git a/libs/sr-formula/tsconfig.lib.json b/libs/sr-formula/tsconfig.lib.json index cd30a2d8ec..f642dfbee1 100644 --- a/libs/sr-formula/tsconfig.lib.json +++ b/libs/sr-formula/tsconfig.lib.json @@ -2,7 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "outDir": "../../dist/out-tsc", - "types": ["node"] + "types": ["node", "object-overrides"] }, "include": ["src/**/*.ts"], "exclude": ["vitest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"] diff --git a/libs/sr-srod/package.json b/libs/sr-srod/package.json new file mode 100644 index 0000000000..477c3c887a --- /dev/null +++ b/libs/sr-srod/package.json @@ -0,0 +1,5 @@ +{ + "name": "@genshin-optimizer/sr-srod", + "version": "0.0.1", + "type": "commonjs" +} diff --git a/libs/sr-srod/project.json b/libs/sr-srod/project.json index 940c9a9ed5..256f675080 100644 --- a/libs/sr-srod/project.json +++ b/libs/sr-srod/project.json @@ -4,6 +4,12 @@ "sourceRoot": "libs/sr-srod/src", "projectType": "library", "targets": { + "build": {}, + "build-ts": { + "options": { + "updateBuildableProjectDepsInPackageJson": true + } + }, "lint": { "executor": "@nx/linter:eslint", "outputs": ["{options.outputFile}"], diff --git a/tsconfig.base.json b/tsconfig.base.json index 447bf98bc6..bf184aee74 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -25,6 +25,7 @@ "exactOptionalPropertyTypes": true, "strictNullChecks": true, "allowSyntheticDefaultImports": false, + "typeRoots": ["./node_modules/@types", "./node_modules", "./types"], "paths": { "@genshin-optimizer/char-cards": ["libs/char-cards/src/index.ts"], "@genshin-optimizer/consts": ["libs/consts/src/index.ts"], diff --git a/types/object-overrides/index.d.ts b/types/object-overrides/index.d.ts new file mode 100644 index 0000000000..096f886cd3 --- /dev/null +++ b/types/object-overrides/index.d.ts @@ -0,0 +1,22 @@ +declare global { + interface ObjectConstructor { + keys(o: Partial>): `${K}`[] + keys( + o: Partial> | Record + ): `${K}`[] + values( + o: Partial> | Record + ): V[] + values( + o: Record> + ): Exclude[] + entries( + o: Record> + ): [`${K}`, Exclude][] + entries( + o: Partial> | Record + ): [`${K}`, V][] + } +} + +export {}