Skip to content

Commit 0f0aba8

Browse files
committed
feat: update validation method to use generic types for improved type safety
1 parent 54db379 commit 0f0aba8

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { RulesForData, Validator } from 'kanun'
2+
13
import { Controller } from 'clear-router'
24
import { HttpContext } from 'clear-router/types/express'
3-
import { Validator } from 'kanun'
45

56
export class BaseController extends Controller<HttpContext> {
6-
// oxlint-disable-next-line typescript/no-explicit-any
7-
async validate<X extends Record<string, any>> (rules: X) {
7+
async validate<D extends Record<string, any>, R extends RulesForData<D>> (rules: R) {
88
return Validator.make(this.body, rules).validate()
99
}
10-
}
10+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { RulesForData, Validator } from 'kanun'
2+
13
import { Controller } from 'clear-router'
24
import { HttpContext } from 'clear-router/types/h3'
3-
import { Validator } from 'kanun'
45

56
export class BaseController extends Controller<HttpContext> {
6-
// oxlint-disable-next-line typescript/no-explicit-any
7-
async validate<X extends Record<string, any>> (rules: X) {
7+
async validate<D extends Record<string, any>, R extends RulesForData<D>> (rules: R) {
88
return Validator.make(this.body, rules).validate()
99
}
10-
}
10+
}

0 commit comments

Comments
 (0)