Everyone's talking about ArkType

Поділитися
Вставка
  • Опубліковано 16 кві 2023
  • ArkType is a brand-new competitor to Zod, with an extremely innovative syntax and some extraordinary TypeScript magic.
    Docs: arktype.io/
    GitHub: github.com/arktypeio/arktype
    Become a TypeScript Wizard with my free beginners TypeScript Course:
    www.totaltypescript.com/tutor...
    Follow Matt on Twitter
    / mattpocockuk
    Join the Discord:
    mattpocock.com/discord

КОМЕНТАРІ • 137

  • @davidblass4552
    @davidblass4552 Рік тому +95

    Hey everyone! Thanks for all of the feedback, it's really helpful 😊
    I know the documentation is really lacking at the moment (working on fixing it for the next release ASAP!). In the meantime, while certainly not a substitute, I'd be happy to answer any questions you have here.
    Thanks again to Matt, not just for making this video but in general- it's been amazing to have so much more consumable high-quality content on the TS ecosystem than there was in years past 💖

    • @dalebradleygordon
      @dalebradleygordon Рік тому +3

      Nifty work man!👏🏻 Always great to see fresh takes on recurring problems 😎

    • @Erandros
      @Erandros Рік тому +1

      nice work man, the things people do with typescript blows my mind sometimes

    • @1879heikkisorsa
      @1879heikkisorsa Рік тому +1

      Awesome work!

    • @LehmannMr
      @LehmannMr 6 місяців тому

      Documentation is still the main issue why I would prefer Zod.

  • @deriegle
    @deriegle Рік тому +185

    It’s really impressive that this is possible, but I’d still prefer zod.
    Being able to see all your options with autocomplete makes life so much easier. ArkType has its own type of language you’d have to learn and just know.

    • @reapi_com
      @reapi_com Рік тому

      Ark might be a good choice for runtime typing. But very niche scenario.

    • @modernkennnern
      @modernkennnern Рік тому +10

      @@reapi_com that's what Zod does too

    • @davidblass4552
      @davidblass4552 Рік тому +11

      I think part of the context that might be missing is that it's an expanded version of TypeScript syntax, so unions, intersections, arrays, literals etc. all work and are inferred exactly the way they are in TS natively, and all keywords have built-in autocomplete, which helps a lot with discoverability!
      I will be adding some options for chaining in the next release for complex scenarios with multiple objects, but goal of the library is to build off of TypeScript's own syntax, supplementing it with runtime constraints like "0

    • @purduetom90
      @purduetom90 Рік тому +1

      couldn't the last part of your statement, "... its own language...that you have to learn and know", also be said about Zod?

  • @willkuerlich
    @willkuerlich Рік тому +8

    A big thank you for keeping us updated on the typescript eco-system!!! Great work Matt

  • @wlockuz4467
    @wlockuz4467 Рік тому +22

    I like the novelty of this but this would be a hell to maintain because its essentially a language of its own.

    • @davidblass4552
      @davidblass4552 Рік тому +4

      It's almost entirely just based on TypeScript's own syntax. Only runtime specific features like bounds, divisibility, etc. have a custom syntax that should be intuitive based on normal runtime checks in JS/TS (the range in the example should have been "0

    • @eliberkowitz7454
      @eliberkowitz7454 Рік тому +4

      The fact that the bound in the video was incorrect is a perfect example of how this could go wrong. What's the advantage of this syntax..?

    • @wlockuz4467
      @wlockuz4467 Рік тому +2

      @@davidblass4552 But why? What is wrong with libraries like zod?
      z.number().min(0).max(200) is so intuitive to understand compared to a simple string which will have runtime implications. Personally it would drive me nuts.

    • @davidblass4552
      @davidblass4552 Рік тому +8

      @@wlockuz4467 Well I think what is familiar to people is always going to feel more intuitive, so that is certainly a barrier we will have to overcome.
      That said, I don't think most devs familiar with any language (or even non-developers) would be confused by what "0

  • @franky47
    @franky47 Рік тому +2

    For the use-case in the thumbnail (marshalled object version field), I found replacing it with a versioned URL to a JSON Schema under the standard $schema key to be great for self-documentation and autocompletion.

  • @zheil9152
    @zheil9152 Рік тому +185

    Meh. I find chaining methods to be cleaner

    • @ayushdedhia25
      @ayushdedhia25 Рік тому +9

      That's true and easy to read

    • @ricardomonge2769
      @ricardomonge2769 Рік тому +1

      Agreed, much better

    • @plusquare
      @plusquare Рік тому +2

      40kb of js

    • @davidblass4552
      @davidblass4552 Рік тому +16

      I think part of the context that might be missing is that it's an expanded version of TypeScript syntax, so unions, intersections, arrays, literals etc. all work and are inferred exactly the way they are in TS natively.
      I will be adding some options for chaining in the next release for complex scenarios with multiple objects, but goal of the library is to build off of TypeScript's own syntax, supplementing it with runtime constraints like "0

    • @MrHellmager
      @MrHellmager Рік тому +1

      Hard agree

  • @brianlaw4706
    @brianlaw4706 Рік тому +2

    I'm glad I'm not the only one who found the docs to be a little...wanting. That said, it's still a really promising project!

  • @tordjarv3802
    @tordjarv3802 Рік тому +4

    The mathematician in me screams when he sees "number>00 && 0 0 && number

  • @alexanderkomanov4151
    @alexanderkomanov4151 Рік тому

    Amazing! Thanks!

  • @andygr1n1
    @andygr1n1 Рік тому +1

    looks good. Thanks for sharing

  • @souravdas423
    @souravdas423 Рік тому

    Hey Matt, love your TS videos, one request please make some videos on Custom AST Compiler for Typescript. WE don't have much video resources around that

  • @skowne
    @skowne Рік тому +2

    This is literally the first I ever hear about ArkType :) Speaking about Zod competitors, have you tried typebox? If so what did you think of it? Fastify recommends it so I use it in my backends, but like Zod's syntax more.

    • @davidblass4552
      @davidblass4552 Рік тому +1

      I think TypeBox is great! Really well-designed and definitely an underrated validator in my opinion.

  • @Mitsunee_
    @Mitsunee_ Рік тому

    I wonder if/how they'll do transformations. zod handles those amazingly, tho I haven't tried async transformations yet (simply didn't need them).

  • @hamesjetfield0
    @hamesjetfield0 Рік тому +3

    I'm not sure about the value of validations using a custom string syntax when Zod already has `.refine` which allows you to narrow down the domain of your type with plain JS/TS.

    • @davidblass4552
      @davidblass4552 Рік тому +2

      Similar functionality exists in ArkType:
      narrow("string", (s) => s.startsWith("foo"))
      In our upcoming release it will be:
      type("string").filter(s => s.startsWith("foo"))

  • @cas818028
    @cas818028 Рік тому +1

    Oh thank god, it has been 6 minutes and 32 seconds since a new JS lib has been released. I was really starting to get anxious.

  • @JohanNordberg
    @JohanNordberg 11 місяців тому

    What are some use cases for this?

  • @PhilipAlexanderHassialis
    @PhilipAlexanderHassialis Рік тому

    Looks good, but going through a rudimentary browsing of the docs I don't see the ability to create my own custom failed validation messages, which, depending on the use case can be a blocker.

  • @helleye311
    @helleye311 Рік тому +2

    This is pretty wild. doing type-level string interpolations is not that easy, I'd personally stay away from anything more than maybe creating dynamic keys based on existing ones. I guess just parsing out type number from "number>0

    • @ctpaintball4life
      @ctpaintball4life Рік тому

      Type level string interpolation is arguably the only thing that is intuitive to do in typescript.

  • @tiriana2
    @tiriana2 Рік тому +1

    I'm not a fan 'number>0

    • @davidblass4552
      @davidblass4552 Рік тому +2

      Yeah this should be a syntax error actually, double bounds are meant to be defined as "0

  • @Kampouse
    @Kampouse Рік тому

    typecript wizard on top of the game again

  • @vim55k
    @vim55k Рік тому +1

    Please continue showing us new stuff

  • @peterjwest3
    @peterjwest3 Рік тому +4

    Impressive library, but I much prefer having zod's structured data than complex strings you'd have to parse to get the raw data back of out.

    • @Scuubie
      @Scuubie Рік тому

      The data you pass is the same, and the "number>0

  • @ntgdpl
    @ntgdpl Рік тому +2

    Started watching since HOTScript

  • @VerhoevenSimon
    @VerhoevenSimon Рік тому

    Out of curiousity, since you've already answered it for someone that's familiar with Zod. Would you recommend Zod or ArkType for someone that's used neither so far. (given one puts faith in the documentation of ArkType being improved)

  • @SkyyySi
    @SkyyySi Рік тому +2

    I'm surprised it can lint your strings, but not give syntax highlighting.

    • @davidblass4552
      @davidblass4552 Рік тому +1

      It's not a plugin, it's just TypeScript's type system giving that feedback.
      Unfortunately, as far as I'm aware TypeScript does not have an ability to add syntax highlighting based on generic types :P

  • @edgeeffect
    @edgeeffect Рік тому

    That looks rather nice... if nothing else, you've made me think "ooooh.... so what's Zod?"

  • @exhaustedrose
    @exhaustedrose Рік тому +1

    does this mean all types can now be defined as JSON?

    • @davidblass4552
      @davidblass4552 Рік тому +1

      One of the primary benefits of ArkType's syntax is its serializability! It could eventually even be used across languages.

  • @anafro_ru
    @anafro_ru Рік тому +1

    Ha, it looks really like Laravel validation strings:
    'age': 'required|min:0|max:99'
    I like that TS stuff :D

  • @morganbartholomew2892
    @morganbartholomew2892 Рік тому +3

    Make a video about Typia, it's this extremely based and way better than Zod tool that makes the types sound.

    • @mattpocockuk
      @mattpocockuk  Рік тому +1

      Docs are pretty rough! And I'm not a huge fan of needing a TS plugin for my library.

  • @mak8naf0813
    @mak8naf0813 Рік тому

    0:55 craaayzyyy 🤣

  • @thelinuxlich
    @thelinuxlich Рік тому +5

    Do a second video showing how Arktype automatically does discriminated unions(and recursively discriminates) and how you compose types with scope() and you might be sold on it

  • @BoonBoonitube
    @BoonBoonitube Рік тому

    I've just recently learned about Zod and now there's already a replacement?

  • @RedStone576
    @RedStone576 Рік тому +1

    sheeesh that is so cool

  • @anj000
    @anj000 Рік тому

    One thing - would be nice to introduce Zod in this video. It is referenced couple of times and I almost bounced of this video because I have no idea what Zod is.

  • @jackgoodall4101
    @jackgoodall4101 Рік тому

    Have you head of Deepkit? they're doing some real typescript magic to achieve this kind of thing for their ORM and validation

  • @the-old-channel
    @the-old-channel Рік тому +1

    Check out superstruct

  • @colinmcd94
    @colinmcd94 Рік тому

    @davidblass4552 Putting the question mark in the key to indicate optionality 🤌 Is there a way to represent "question-mark-less" optionality? e.g. { name: string | undefined }? Zod can't do this either yet.

    • @davidblass4552
      @davidblass4552 Рік тому

      Yes built-in TypeScript syntax just works, you can define "string|undefined"

  • @seannewell397
    @seannewell397 Рік тому +1

    That's friken cooooool. Can arktype accept a type like HexChar to constrain strings too? Or just pass a type? Since this is just a function, these 'types' by dynamically generated as well which blows my mind up xD
    ```ts
    type HexChar = 'a' | 'b' | 'c' |... | 'f' | '0' | '1' | ... | '9';
    const UserTag = type({
    char: HexChar,
    name: 'string'
    });
    ```

    • @mattpocockuk
      @mattpocockuk  Рік тому

      It can constrain strings by regex, which is fairly nuts.

  • @ColinRichardson
    @ColinRichardson Рік тому +1

    Wazzup

  • @Troncoso01
    @Troncoso01 Рік тому +2

    1:18, I would have put the ? syntax on "string" instead of the property name...

    • @tamicktom
      @tamicktom Рік тому +1

      Agree. It would be more intuitive.

    • @RedOchsenbein
      @RedOchsenbein Рік тому

      Yeah, I'm in the same boat. However, I guess this way is just closer to the typescript syntax.

    • @davidblass4552
      @davidblass4552 Рік тому +1

      I've thought so much about the specific trade offs here. I might allow that as an alternate syntax, but in general the default is to be as close to 1:1 with TypeScript as possible, and logically the mode should be that the optionality belongs to the key, not to the value.
      That said, having to quote your keys 😭

    • @Troncoso01
      @Troncoso01 Рік тому

      @@davidblass4552 I mean, this syntax isn't very typescript-y to begin with. You are providing properties and the possible values of them. A ? would mean this property can be "undefined", so it still is a reference to the value. To me the downside besides the quoting is the consistency. The left is the property, the right is the rules for what that property's value can be, except for this particular rule.

    • @davidblass4552
      @davidblass4552 Рік тому

      @@Troncoso01
      TypeScript:
      type user = {
      age?: number
      }
      ArkType:
      const user = type({
      "age?": "number"
      })
      It is definitely optimal from a TS-syntax 1:1 perspective, which is a big part of the goal of the library. Arrays, unions, intersections literals etc. work the same way

  • @anafro_ru
    @anafro_ru Рік тому

    1:36
    Matt *writing code*
    IDE: problems?
    xD

  • @SamyarBorder
    @SamyarBorder Рік тому +4

    honestly this seems easier than zod

    • @mattpocockuk
      @mattpocockuk  Рік тому +2

      Yeah I think this is going to be a lot of folks' reactions. I personally prefer Zod's syntax - and obviously it's a more mature library. But having a worthy competitor is always great.

    • @ColinRichardson
      @ColinRichardson Рік тому +1

      There are a few downsides currently.. Stuff like `type('[string, string, number][]')` currently would not work.

    • @reapi_com
      @reapi_com Рік тому

      First zod allow your to defined property level error message.

  • @dealloc
    @dealloc Рік тому

    What killed the idea for me is that is uses strings. They are not composable unlike Zod, where you keep the type around and can extend it further. There are cases where I pass partial Zod types as arguments and whatever function can extend it further if need be.

    • @davidblass4552
      @davidblass4552 Рік тому

      We will be supporting chaining in our next release! The goal is to have any definition that can be defined as a 1:1 with TypeScript done that way, but stuff like this is definitely really nice with chaining syntax IMO:
      type({
      a: "string",
      b: "number"
      }).filter(data => data.a === "foo").morph(data => ({a: data.b, b: data.a}))
      This would automatically be inferred as {a: number, b: string} when validated

  • @franciscokloganb
    @franciscokloganb 10 місяців тому

    I will keep zod thanks

  • @luctielen
    @luctielen Рік тому

    I still prefer zod due to better autocomplete, and I think better runtime perf too (this all has to be parsed and evaluated at some point!)

    • @luctielen
      @luctielen Рік тому

      @@davidblass4552 oh dang, thanks for pointing that out. I should've looked up their docs before throwing my assumptions out there.
      (But I do hope we can get a similar API to zod at some point 😅)

  • @bansh3ee
    @bansh3ee Рік тому

    and I'm still stuck with Joi

  • @jwueller
    @jwueller Рік тому +3

    I don't see the advantage or appeal of encoding all of this information in a string, to be honest. I would really rather have standard language features like validation functions that editors and other programmers will natively understand.

  • @DeathSugar
    @DeathSugar Рік тому

    Year 2023. People rediscover reflection types once again...

  • @tacticaltaco7481
    @tacticaltaco7481 Рік тому

    Intellisense will become old news if copilot-like tools become good enough.

    • @RedOchsenbein
      @RedOchsenbein Рік тому

      Nope. Because Copilot would not be able to keep up with all the documentation changes of all the libraries. And parsing them all, send them over the network, to get predictions about your code back would be crazy.

    • @tacticaltaco7481
      @tacticaltaco7481 Рік тому

      @@RedOchsenbein There's no reason it couldn't keep up with documentation changes with the right architecture. I was a bit sensationalist as it would most likely augment intellisense, but making architecture decisions contingent on intellisense capabilities will become unnecessary.

  • @mattd5419
    @mattd5419 Рік тому +5

    from a Typescript perspective is impressive, but the syntax is actually terrible. Zod is much more readable IMO.

  • @fabriziotofanelli
    @fabriziotofanelli Рік тому

    Hey wizard! Mind to make your wizardry in this video - v=B7ygRIQcQPE , please? I loved it but somehow I missed some point and everything went weird after some part 😅

  • @sunny7268
    @sunny7268 Рік тому

    That looks good, but typos will destroy this approach, so no thank you, by the way, why does everyone prefer ZOD over AJV?

    • @davidblass4552
      @davidblass4552 Рік тому

      That's why there's autocomplete and syntax validation, so it's >= the level of type-safety you get natively writing definitions in your IDE!

  • @soniablanche5672
    @soniablanche5672 Рік тому +2

    so is zod officially dead ?

  • @dancarter5595
    @dancarter5595 Рік тому

    Great, another proprietary syntax for yet another library that can already be done in a more widely adopted fluent API.

    • @davidblass4552
      @davidblass4552 Рік тому

      It's not proprietary and it' just reuses TypeScript's own syntax for things like arrays, unions, intersections, literals, etc.
      Stuff like "0

  • @DavidWTube
    @DavidWTube Рік тому +4

    This is one of those things that makes me pose the question "What's wrong with vanilla javascript?". Why import an obscure library that makes people have to go read docs vs just looking at and understanding your code? This is the type of stuff that causes prod errors. Neat but not practical.

    • @rafaeltab
      @rafaeltab Рік тому +7

      I get where you're coming from here. I really do. But having a 100 if statements check that your types are correct isn't practical, and it is more difficult to understand than this library. I also went the route of just doing it myself, and it bit me in my ass quite thoroughly. Having this library provides a predictable list of problems that your input created. This list of problems is essential when using an API. Too often have I had to use an API that just said "Your input is wrong, try again", and if this takes a step towards ending that, I'll gladly take it.

    • @FeralWitchchild
      @FeralWitchchild Рік тому +2

      "just looking at and understanding your code" It's not feasible if your codebase is hundreds of thousands of lines of code and you have more than 10 people working on it.

    • @avi7278
      @avi7278 Рік тому +4

      Lol this mid level developer is going through one of the phases before our very eyes.

    • @DavidWTube
      @DavidWTube Рік тому

      @avi7278 yeah... that's it. You got me...

    • @hojdog
      @hojdog Рік тому

      Why use typescript for that matter. Why use React. I can just do it in vanilla js. Why even use js, i can just use php. But why use php if I can use a rock and a stick?

  • @matbeedotcom
    @matbeedotcom Рік тому

    Zip this video up a bit and make it a UA-camShort

  • @HaNdTriXo
    @HaNdTriXo Рік тому

    ArkType is based on eval afaik. This is a real bummer since it will be a no-go for many security related projects. (#CSP)

    • @davidblass4552
      @davidblass4552 Рік тому +2

      It's not on main, but on the perf branch we are implementing a strategy that uses the Function constructor to optimize perf (this allows it to validate 400x faster than Zod).
      We'll add an option to precompile validators altogether though to avoid parsing at runtime entirely, so shouldn't be a blocker.

    • @HaNdTriXo
      @HaNdTriXo Рік тому +2

      @@davidblass4552 wow cool this sounds awesome!

  • @HiImKyle
    @HiImKyle Рік тому

    It's cool but it'll never replace zod

  • @portersky
    @portersky Рік тому +1

    bro, that's black magic

  • @repe0
    @repe0 Рік тому

    Another day, another new library. No thanks 😂

  • @darksinge
    @darksinge Рік тому

    But why?... 😂

  • @Spectraevil
    @Spectraevil Рік тому +3

    Typescript ecosystem loves to over complicate things and build gimmicky things. Though it looks like a fun library, why would u want to include these checks inside the type strings? Work in Java for a while, u will realise all these things r not needed and ur programming will improve. Most of the typescript gimmick features can be easily handled using interfaces and abstract classes.

    • @Cassp0nk
      @Cassp0nk Рік тому

      Java is a severely outdated language. You are behind the curve bro.

    • @Spectraevil
      @Spectraevil Рік тому +1

      @@Cassp0nk lol java is not outdated. If u want a good senior backend engineering job at majority of big tech companies, u need java. Majority of bit tech companies, investment banks and all use java as their core backend language, with python, go, nodejs etc for some services. Majority of tech companies including google, amazon use java as their core backend language, facebook uses Hack/php, microsoft uses C#.
      P.S: I have worked in JS, Python, Java, Ruby, Scala at my jobs over the years.

  • @Metruzanca
    @Metruzanca Рік тому +1

    Feels like someone really enjoys Rust macros, but is forced to write typescript.

  • @polioann
    @polioann Рік тому

    zod is nice till u need a custom errors loool

  • @aryankathawale9269
    @aryankathawale9269 Рік тому

    bruh , zod replaced 😭😭😽😽

  • @avi7278
    @avi7278 Рік тому

    Gonna have to do better than "it's different" in relation to zod. I doubt I'll ever go away from zod. Let's stop somewhere. How about that?

  • @Rundik
    @Rundik 11 місяців тому

    "email?": is increadably ugly

  • @tropicbliss1198
    @tropicbliss1198 Рік тому +2

    gives the term stringly typed a whole new meaning 🥲

  • @WesSouza
    @WesSouza Рік тому

    No, no no no, no.

  • @StephenWillians
    @StephenWillians Рік тому

    Nah, dont think that string validation is a good thing

  • @additionaddict5524
    @additionaddict5524 Рік тому

    Ew

  • @no_way_to_exist
    @no_way_to_exist Рік тому

    zod is much better

  • @zlackbiro
    @zlackbiro Рік тому

    Does it run on runtime? No! Useless...