Hookyns / tst-reflect

Advanced TypeScript runtime reflection system
MIT License
338 stars 11 forks source link

is there a typescript runtime validator? #57

Closed masx200 closed 2 years ago

masx200 commented 2 years ago

is there a typescript runtime validator?

Hookyns commented 2 years ago

Hi, what kind of validator you mean? To validate what? Schemas? Data? Validate by some rules or just by TS types?

masx200 commented 2 years ago
const validator=new Validator<{foo:string,bar:number}>()

validator.validate(JSON.parse("something"))
validator.validate({foo:"something",bar:999})
Hookyns commented 2 years ago

There is no such validator inside this project. This project is clear Reflection system.

Validator might be some other package using this package to implement the validation. But such validation is quite simple and you can use built in Type.isAssignableTo(someOtherType) and runtime type construction via getType(some runtime value).

Check this https://stackblitz.com/edit/tst-reflect-validation?file=index.ts.

But those are quite experimental features.

Hookyns commented 2 years ago

But maybe you can use https://github.com/joeferner/tst-reflect-json-schema-generator and then u can use existing schema validators or maybe you'll find useful this https://github.com/ciricc/tst-defaults.

masx200 commented 2 years ago

https://www.npmjs.com/package/typescript-is