Skip to content

Infer types from Typescript instead of explicitly declaring #130

@kirillgroshkov

Description

@kirillgroshkov

It's probably a not very easy thing to do, but ultimately it would be great to utilize Typescript typings instead of explicitly declaring validation types.

Instead of:

@IsString()
a: string

Just:

a: string // @IsString() inferred, also @IsDefined inferred

b?: string // @IsString(), @IsOptional inferred from "?"

I was able to achieve that in a long way, by:

  1. Using https://github.com/YousefED/typescript-json-schema during build step to generate json schemas, that know about types, also if fields are required or not, and some more things.
  2. Use json-schema validator in runtime (there are many) that consume schema generated in step 1 and give validation errors.

Result is that I have type and required/optional validation "inferred" from Typescript.

Any ideas how to achieve that with class-transformer, to utilize the beauty of @annotations (to combine inferred types with custom annotations and use all other features of class-transformer).

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questionQuestions about the usage of the library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions