Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't allow additional parameters #2491

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question but isn't this the default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, afaik, it is. This line can probably be removed.

"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