Это видео недоступно.
Сожалеем об этом.
Validating JSON with TypeScript Interfaces; JSON Schema, TSDoc
HTML-код
- Опубликовано: 14 авг 2024
- 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 (github.com/You...) is used to convert the TypeScript interfaces to JSON Schema (json-schema.org). Once the JSON Schema exists AJV (github.com/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 (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! (www.signaladvi...)
Ryan Burr is Director of Engineering at Signal Advisors and a TypeScript enthusiast.
Recorded on October 4th 2022 at Cahoots (cahoots.com) in Ann Arbor, Michigan.
Discord: / discord
Twitter: / mitypescript
Mastodon: fosstodon.org/...
Instagram: / michigantypescript
TikTok: / michigantypescript
I wonder if this guy has considered Zod? You can write the schema in JS and do a z.infer 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.
thanks for the edit, but if you have time you should totally reach out to Ryan and show him Zod. I know he'd love to see it, genuinely.
Genius. Simple. I am going to implement this for my company. Thank you.
let us know how it goes!
Have u considered using class validator for this purpose?
but then you have to use classes.....
Why use this when you use Zod? It's much better for validations.
did you see the audience question on exactly that?
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..
Recruiting strategy
you can skip it, if u dont like it
@@michalkotlicki4710 Doesn't answer the question of "why" ..
@@ColinRichardson Win-win-win for everyone. Nobody is entitled, only blessed with well-designed solutions such as this. Entertain everything this guys says in this talk, even the recruitment pieces. Everyone wins. It's not rocket surgery. The problem you have is with people who present themselves and then provide fluff. This is legit.
@Joseph doesn't answer the question of "why"
the "function" key word Cringeee.
lolol totally agree. some habits die hard. and thanks to the snafu with the syntax for async generator arrow functions we're stuck with the function keyword (probably) forever
Nah
he need to stop saying "um"
that's a fair criticism for almost any speaker. it's harder to do than it seems!
@@MichiganTypeScript i agree