Skip to content

Commit

Permalink
fix: don't allow additional parameters in plain client (#2491)
Browse files Browse the repository at this point in the history
  • Loading branch information
andipaetzold authored Dec 3, 2024
1 parent 5f62ca1 commit 885335c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
30 changes: 30 additions & 0 deletions lib/plain/wrappers/wrap.test-d.ts
Original file line number Diff line number Diff line change
@@ -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<Expected>().toMatchTypeOf<Result>()
})

it('adds default props if available', () => {
type Result = OptionalDefaults<{
foo: string
environmentId: string
}>

type Expected = {
foo: string
environmentId?: string
}

expectTypeOf<Result>().toMatchTypeOf<Expected>()
})
})
4 changes: 1 addition & 3 deletions lib/plain/wrappers/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ export type DefaultParams = {
* @private
*/
export type OptionalDefaults<T> = Omit<T, keyof DefaultParams> &
('organizationId' extends keyof T ? { organizationId?: string } : Record<string, unknown>) &
('spaceId' extends keyof T ? { spaceId?: string } : Record<string, unknown>) &
('environmentId' extends keyof T ? { environmentId?: string } : Record<string, unknown>)
Partial<Pick<T, Extract<keyof T, keyof DefaultParams>>>

/**
* @private
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
11 changes: 11 additions & 0 deletions vitest.workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 885335c

Please sign in to comment.