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,