From 885335c4816b8d166147621e556cafced9123a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andi=20P=C3=A4tzold?= Date: Tue, 3 Dec 2024 13:36:41 +0100 Subject: [PATCH] fix: don't allow additional parameters in plain client (#2491) --- lib/plain/wrappers/wrap.test-d.ts | 30 ++++++++++++++++++++++++++++++ lib/plain/wrappers/wrap.ts | 4 +--- package.json | 3 ++- tsconfig.json | 3 ++- vitest.workspace.js | 11 +++++++++++ 5 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 lib/plain/wrappers/wrap.test-d.ts diff --git a/lib/plain/wrappers/wrap.test-d.ts b/lib/plain/wrappers/wrap.test-d.ts new file mode 100644 index 0000000000..14c220e06e --- /dev/null +++ b/lib/plain/wrappers/wrap.test-d.ts @@ -0,0 +1,30 @@ +import { describe, expectTypeOf, it } from 'vitest' +import type { OptionalDefaults } from './wrap' + +describe('OptionalDefaults', () => { + it('does not add props', () => { + type Result = OptionalDefaults<{ + foo: string + }> + + type Expected = { + foo: string + } + + expectTypeOf().toMatchTypeOf() + }) + + it('adds default props if available', () => { + type Result = OptionalDefaults<{ + foo: string + environmentId: string + }> + + type Expected = { + foo: string + environmentId?: string + } + + expectTypeOf().toMatchTypeOf() + }) +}) diff --git a/lib/plain/wrappers/wrap.ts b/lib/plain/wrappers/wrap.ts index f23f511423..322a1f18f8 100644 --- a/lib/plain/wrappers/wrap.ts +++ b/lib/plain/wrappers/wrap.ts @@ -10,9 +10,7 @@ export type DefaultParams = { * @private */ export type OptionalDefaults = Omit & - ('organizationId' extends keyof T ? { organizationId?: string } : Record) & - ('spaceId' extends keyof T ? { spaceId?: string } : Record) & - ('environmentId' extends keyof T ? { environmentId?: string } : Record) + Partial>> /** * @private diff --git a/package.json b/package.json index 7c562f3ab0..c17aaf01bd 100644 --- a/package.json +++ b/package.json @@ -37,10 +37,11 @@ "check-types": "tsc", "lint": "eslint lib test --ext '.ts,.tsx,.js,.jsx'", "pretest": "rimraf coverage && npm run lint", - "test": "npm run test:cover-unit && npm run test:cover-integration && npm run test:size", + "test": "npm run test:cover-unit && npm run test:types && npm run test:cover-integration && npm run test:size", "test:cover-unit": "npm run test:unit -- --coverage", "test:cover-integration": "npm run test:integration -- --coverage", "test:unit": "npx vitest --project unit --run", + "test:types": "npx vitest --project types --run", "test:unit-watch": "npx vitest --project unit", "test:integration": "npx vitest --project integration --run --no-file-parallelism", "test:integration-watch": "npx vitest --project integration --no-file-parallelism", diff --git a/tsconfig.json b/tsconfig.json index ff5a8f139c..e21df64f4c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,8 @@ "isolatedModules": true, "esModuleInterop": true, "noImplicitThis": false, - "typeRoots": ["node_modules/@types"] + "typeRoots": ["node_modules/@types"], + "skipLibCheck": true }, "include": ["lib", "global-types"], "typedocOptions": { diff --git a/vitest.workspace.js b/vitest.workspace.js index 9c596923fe..726a31dc7f 100644 --- a/vitest.workspace.js +++ b/vitest.workspace.js @@ -12,6 +12,17 @@ export default defineWorkspace([ maxConcurrency: 10, }, }, + { + test: { + ...vitestConfig.test, + include: ['lib/**/*.test-d.ts'], + name: 'types', + maxConcurrency: 10, + typecheck: { + enabled: true, + }, + }, + }, { test: { ...vitestConfig.test,