typia
typia copied to clipboard
Decorator based usage for typia.functional.assertEqualsFunction
Hello, thank you for maintaining and open-sourcing typia. Really love the DX this library offers.
Feature Request
I am using typia.functional module to guard function parameters and return values.
While this works great for standalone functions, it would be great if we could use this (or a similar utility) as decorators on class methods too.
Suggested API:
class UserService {
@typia.decorators.assertEquals
async findMany(query: UserQuery) {
// We only reach here if query is validated to be UserQuery
}
}
Currently it is possible to do something like this:
class UserService {
findMany = typia.functional.assertEquals(async (query: UserQuery) => {
// We only reach here if query is validated to be UserQuery
})
}
But this doesn't work well if you need other decorators on that method, or need inheritance.
There had been @AssertType() decorator function in typescript-is.
As I am concentrating on AI development, I cannot sure when I can start this ticket, but this idea seems good.