Skip to content

Commit

Permalink
Made the validate function of the ContraintStrategy in the typescript… (
Browse files Browse the repository at this point in the history
#324)

* Made the validate function of the ContraintStrategy in the typescript definition optional (as it is also optional in the js-code) added the validate function in the readme doc

* removed the no-op validate function as it is now correctly optional in the ts-typings

---------

Co-authored-by: Nick <[email protected]>
  • Loading branch information
Nick and Nick authored May 3, 2023
1 parent ef163bc commit 36b8a6c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,10 @@ const customVersioning = {
deriveConstraint: (req, ctx) => {
return req.headers['accept']
},
mustMatchWhenDerived: true // if the request is asking for a version, don't match un-version-constrained handlers
mustMatchWhenDerived: true, // if the request is asking for a version, don't match un-version-constrained handlers
validate (value) { // optional validate function, validates the assigned value at route-configuration (the .on function) time (not the runtime-value)
assert(typeof value === 'string', 'Version should be a string')
}
}

const router = FindMyWay({ constraints: { version: customVersioning } });
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ declare namespace Router {
del?(value: T) : void,
empty?() : void
},
validate(value: unknown): void,
validate?(value: unknown): void,
deriveConstraint<Context>(req: Req<V>, ctx?: Context) : T,
}

Expand Down
1 change: 0 additions & 1 deletion test/types/router.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ let http2Res!: Http2ServerResponse;
deriveConstraint<Context>(req: Router.Req<Router.HTTPVersion.V1>, ctx: Context | undefined): string {
return req.headers.accept ?? ''
},
validate(value: unknown): void {},
storage () {
return {
get (version) { return handler },
Expand Down

0 comments on commit 36b8a6c

Please sign in to comment.