Validating JSON with TypeScript Interfaces; JSON Schema, TSDoc

preview_player
Показать описание
Signal Advisors sends out thousands of notifications to their customers trusting that templates have proper data. This talk walks through how to use TypeScript interfaces with JSDoc (TSDoc) tags to generate schemas and build with confidence.

03:08 defining payload schemas with TypeScript
04:18 the Signal Advisors use case
05:11 converting TypeScript to JSON Schema
07:08 overview of the example repo for this talk
07:50 example 1: two simple interface properties
12:08 example 2: nested interfaces
15:01 example 3: extending interfaces and type literal unions
20:13 example 4a: date formatting validation
22:29 example 4b: email validation
22:59 example 4c: minLength and maxLength on strings
25:09 audience question: how do you publish the schemas?
25:46 audience question: do the 3rd party services have access to the TypeScript types?
27:04 audience question: do you version the schemas?
28:11 audience question: why did you do code-first rather than spec-first?
29:17 audience question: how expressive is JSON Schema compared to TypeScript?
30:00 audience question: what made you use this particular npm?
30:27 audience question: did you look into OpenAPI for this use case?
31:43 audience question: are you also autogenerating documentation from the JSON Schema?
33:01 audience question: do you have anything in CI that runs the schemas against the templates?

Ryan Burr is Director of Engineering at Signal Advisors and a TypeScript enthusiast.

Рекомендации по теме
Комментарии
Автор

Genius. Simple. I am going to implement this for my company. Thank you.

valueconomy
Автор

I wonder if this guy has considered Zod? You can write the schema in JS and do a z.infer<typeof Schema> to get the typescript type. Just one schema, no duplication, and validation at runtime. I guess the cool thing about his approach is the ability to have the schema in a more generic format but if the vast majority of the stack is TS, Zod can clean things up and a bit and remove that schema building step.
EDIT: Should have watched the whole thing first... Seems like they need the generic schema file for other template checks so Zod probably doesn't help in the specific case.

AustinMarlar
Автор

Have u considered using class validator for this purpose?

siddharthskumar
Автор

Why use this when you use Zod? It's much better for validations.

josemonge
Автор

Why on earth EVERY presenter feels they need to announce who they are in great detail at the start of EVERY presentation is beyond infuriating..
I am sure there is a book somewhere that says "How to do presentations 101".. and everyone reads it.. it's too bad the book is just annoying everyone..

ColinRichardson
Автор

the "function" key word Cringeee.

CodeClanWeb