Skip to content

Commit

Permalink
fix: V.properties typing
Browse files Browse the repository at this point in the history
Signed-off-by: Samppa Saarela <samppa.saarela@iki.fi>
  • Loading branch information
ssaarela committed Nov 8, 2024
1 parent 9070e0d commit 757b676
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
7 changes: 6 additions & 1 deletion packages/core/src/V.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,12 @@ describe('objects', () => {
await expectViolations({ property: 'string' }, validator, defaultViolations.unknownPropertyDenied(ROOT.property('property')));
});

test('properties', () => expectValid({ foo: 'bar' }, V.properties(V.string(), V.string())));
describe('properties', () => {
test('valid properties', async () => {
const validator = V.properties(V.string(), V.string());
(await expectValid({ foo: 'bar' } satisfies Record<string, string>, validator)) satisfies Record<string, string>;
});
});

describe('cross-property rules', () => {
interface IPasswordRequest {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/V.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ export const V = {

size: <T extends { length: number }>(min: number, max: number) => new SizeValidator<T>(min, max),

properties: (keys: Validator, values: Validator) => new ObjectValidator({ additionalProperties: { keys, values } }),
properties: <Key extends keyof any, Value>(keys: Validator<Key>, values: Validator<Value>) =>
new ObjectValidator<Record<Key, Value>>({ additionalProperties: { keys, values } }),

allOf: (...validators: [Validator, ...Validator[]]) => new AllOfValidator(validators),

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/testUtil.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function verifyValid<Out>(result: ValidationResult<Out>, value: any, conv
} else {
expect(result.getValue()).toEqual(value);
}
return result;
return result.getValue();
}

test.skip('do not fail build because of no tests found', () => { });
2 changes: 1 addition & 1 deletion packages/luxon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"peerDependencies": {
"@finnair/path": ">=6",
"@finnair/v-validation": ">=6",
"@finnair/v-validation": ">=7",
"luxon": "^3.4.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/moment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"peerDependencies": {
"@finnair/path": "=>6",
"@finnair/v-validation": ">=6",
"@finnair/v-validation": ">=7",
"moment": "^2.30.0"
},
"devDependencies": {
Expand Down

0 comments on commit 757b676

Please sign in to comment.