Validating JSON with TypeScript Interfaces; JSON Schema, TSDoc

Опубликовано: 09 Октябрь 2022
на канале: Michigan TypeScript
7,043
154

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.

To accomplish this, typescript-json-schema (https://github.com/YousefED/typescrip...) is used to convert the TypeScript interfaces to JSON Schema (https://json-schema.org). Once the JSON Schema exists AJV (https://github.com/ajv-validator/ajv) can be used to validate the JSON.

00:00 who is Signal Advisors? (signaladvisors.com)
01:47 building emails with React, MJML (mjml.io) and handlebars.js
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?
32:18 audience question: have you compared this to zod (https://zod.dev TypeScript-first schema validation with static type inference)
33:01 audience question: do you have anything in CI that runs the schemas against the templates?
35:30 Signal Advisors is hiring! (https://www.signaladvisors.com/careers)

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

Recorded on October 4th 2022 at Cahoots (https://cahoots.com) in Ann Arbor, Michigan.

Discord:   / discord  
Twitter:   / mitypescript  
Mastodon: https://fosstodon.org/@MichiganTypeSc...
Instagram:   / michigantypescript  
TikTok:   / michigantypescript  


Смотрите видео Validating JSON with TypeScript Interfaces; JSON Schema, TSDoc онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Michigan TypeScript 09 Октябрь 2022, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 7,04 раз и оно понравилось 15 людям.