Это видео недоступно.
Сожалеем об этом.

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

Комментарии • 26

  • @AustinMarlar
    @AustinMarlar Год назад +5

    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.

    • @MichiganTypeScript
      @MichiganTypeScript  Год назад

      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.

  • @valueconomy
    @valueconomy Год назад

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

  • @siddharthskumar6831
    @siddharthskumar6831 Год назад

    Have u considered using class validator for this purpose?

  • @josemonge4604
    @josemonge4604 11 месяцев назад

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

    • @MichiganTypeScript
      @MichiganTypeScript  11 месяцев назад

      did you see the audience question on exactly that?

  • @ColinRichardson
    @ColinRichardson Год назад +2

    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..

    • @devCulture1
      @devCulture1 Год назад

      Recruiting strategy

    • @michalkotlicki4710
      @michalkotlicki4710 Год назад

      you can skip it, if u dont like it

    • @ColinRichardson
      @ColinRichardson Год назад

      @@michalkotlicki4710 Doesn't answer the question of "why" ..

    • @valueconomy
      @valueconomy Год назад +2

      @@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.

    • @ColinRichardson
      @ColinRichardson Год назад

      @Joseph doesn't answer the question of "why"

  • @CodeClanWeb
    @CodeClanWeb Год назад

    the "function" key word Cringeee.

    • @MichiganTypeScript
      @MichiganTypeScript  Год назад

      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

    • @GustavoDiaz93
      @GustavoDiaz93 Год назад

      Nah

  • @nxxh8019
    @nxxh8019 Год назад

    he need to stop saying "um"

    • @MichiganTypeScript
      @MichiganTypeScript  Год назад +3

      that's a fair criticism for almost any speaker. it's harder to do than it seems!

    • @nxxh8019
      @nxxh8019 Год назад

      @@MichiganTypeScript i agree