Ready to get started?

Join Adocasts Plus for $8.00/mo or sign into your account to get access to all of our lessons.

robot mascot smiling

Typing Lucid Models in Inertia with DTOs

In this lesson, we'll learn how we can specify types for our Lucid Models easily using DTOs we'll generate directly from our models.

Published
Sep 27
Duration
10m 58s

Developer, dog lover, and burrito eater. Currently teaching AdonisJS, a fully featured NodeJS framework, and running Adocasts where I post new lessons weekly. Professionally, I work with JavaScript, .Net C#, and SQL Server.

Adocasts

Burlington, KY

Chapters

00:00 - Why We'll Use DTOs
02:15 - Generating our DTOs from our Models
05:10 - Adding Our Organizations to the DTOs
09:10 - Using Our DTOs

Ready to get started?

Join Adocasts Plus for $8.00/mo or sign into your account to get access to all of our lessons.

Join The Discussion! (4 Comments)

Please sign in or sign up for free to join in on the dicussion.

  1. Commented 3 days ago

    until this part i was amazed how flawlessly AdonisJS works with InertiaJS, but this DTO part for me makes it a little bit non-DRY, I understand the generator package that we installed but still.

    1

    Please sign in or sign up for free to reply

    1. Commented 3 days ago

      I agree, it does make things less DRY, but to my knowledge, in other Inertia-supported environments, you would need to define the type specifically for the frontend as well. At least with AdonisJS, we can convert it to the DTO on the server side to ensure what we're passing matches expectations on the frontend.

      It would be awesome if we could directly access a serialized type of the model, but that would take quite the doing!

      1

      Please sign in or sign up for free to reply

      1. Commented 2 days ago

        By the way thank you for these videos you have great teaching skills. Is it against TS best practices if I create a types/models.d.ts file inside inertia folder and declare my models as global interfaces/types? This way I don't have to import them inside my vue files, just use them.

        1

        Please sign in or sign up for free to reply

        1. Commented 1 day ago

          That means a lot, thank you, tibormarias! Also, thank you for watching & being an Adocasts Plus member, it's greatly appreciated! Yeah, if you'd rather not use DTOs, I think that's a perfectly viable alternative approach.

          0

          Please sign in or sign up for free to reply