I'm curious if there exists a way to specify the format that an interface property should adhere to. For instance:
interface User {
age?: number,
name: string,
birthdate: string // must be in 'YYYY-MM-DD' format
}
I came across decorators, but it seems they are only applicable to classes, not interfaces.
I am working on developing an API using node/express and require input validation. Therefore, I am looking into Celebrate, which can utilize joi type Schema for input validation. However, I prefer to define my Schema / view model using TypeScript instead... As you can see, I am trying to use an Interface to outline what the input of a specific endpoint should resemble:
- age: number, can be omitted
- name: string
- birthdate: string in the "YYYY-MM-DD" format
Any assistance or advice would be greatly appreciated :)