Everyone's talking about HOTScript

Поділитися
Вставка
  • Опубліковано 13 кві 2023
  • HOTScript: github.com/gvergnaud/hotscript
    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

КОМЕНТАРІ • 142

  • @ChillAutos
    @ChillAutos Рік тому +196

    Beautiful in the most scary kind of way. Most TS devs I know barely understand generics. I dont expect to see this in our code base for another 10years.

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

      You mean in production code?

    • @axios7776
      @axios7776 Рік тому +20

      I think these kinds of utility types are mostly for libraries that have to support a variety of consumers

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

      Higher order types could actually be useful in quite regular code. For example, type T = A isn't possible without higher order types and you don't have to be a genius to figure out what it does

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

      @@peterjasko7059 I am far from a genius. What does it do? Or is that the point?

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

      ​@@GavinKing_AKA_plumpNation : Looks like T is just a buffer of sorts. Not knowing Typescript, I assume that A< B > results in a type being defined, at which point I'm forced to suspect that that the provided example implies that Typescript doesn't support type descriptors as a data type.

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

    I feel like it would be much more desirable to just have proper compile-time meta-programs written in actual TypeScript instead of trying to essentially duplicate the entire language in the type system.
    This is a trap that many type systems seem to fall into. Sooner or later they become Turing-complete, because people understandably want to do arbitrarily complex things. Then they start writing meta-programs in the type system, which is just not designed for that kind of work.
    You're essentially forcing the compiler to do compile-time code execution, but in the most convoluted way possible. Compilation times will suffer massively (see C++ templates and similar systems).

  • @yumeyuki1944
    @yumeyuki1944 Рік тому +13

    Me: Looks nice
    TS LSP:
    TS LSP but 10 minutes later: Agree

  • @MobiusCoin
    @MobiusCoin Рік тому +78

    TypeScript is reminding me more and more of my thousands of hours painting my 40k miniatures and my paltry couple dozen hours actually playing the game.

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

      Lmao that’s so accurate

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

      It's true! The sort of nice thing about that is that you are painfully aware that type-space work is intrinsically 'useless', instead of thinking your doing something useful by following big boilerplatey OOP patterns - instead there is this big line between inert typing code and active js code

  • @culi7068
    @culi7068 Рік тому +23

    I think freewheeling is totally fine as long as you're showing something valuable. In this case you introduced me to a new pattern in TypeScript. I'd love to see you analyze more bleeding edge TypeScript libraries and just talk about new/emerging/interesting patterns being used

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

    Great format Matt, hoping to see more!

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

    This is a great video for me a senior typescript dev looking to stay in the know. Keep them comming :)

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

    Definitely here for this style of video as well!!

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

    As a functional programming enthusiast since 2012..I dig this so far. Also, I like this style of video too. Good on ya mate.

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

    To quote my favorite show my kids watched, “But why?”

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

    I really liked this recommendation and how you presented it, no need for heavy editing! I will think about how I could use this in one of my projects.

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

    I like this type of video, cause it tells me about cool things I could look for and use in the future without me having to go around the internet discovering everything myself. I really like your videos. I think I never really knew much about typescript as much as I do now. I don't think I'm a wizard tbh, I'm more like a casual observer who uses this stuff. Many more people better than me. But I do like listening and learning all the same. Great job!

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

    Yes, like this style of video. always great to stay up to date

  • @Alec.Vision
    @Alec.Vision Рік тому +9

    Oh, I've GOT to use this in my lib. I knew this kind of thing was possible, I just wrote a type that creates recursive types with multiple recursion points at any level of nesting (to get around the limitations of, e.g., Zod Lazy) but this Library will save me hours and hours of creating complex type incantations. Maybe I'll have a few of my own to contribute!

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

    More like this! Great work, Matt! 👍👍👍

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

    I used this for code-golf a while back and was very impressed by how useful it is. It turns TS into a functional programming language.

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

    yes, please more of those videos. "the community is talking about it but you've been busy, let's sum it up in 3 minutes" is the perfect angle for me.

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

    I like this style of video, and the content. Keep up the good work :)

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

    This looks like one of those things that I stare at for ages thinking "yeah... but what the hell is it FOR?" until some "wizard" comes along and say "oh, it's for THIS" and shows me something amazing. ;)

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

    Thanks, Matt. I'm going to check this out, too.

  • @artu-hnrq
    @artu-hnrq 11 місяців тому

    I like these videos!!
    Jeep sharing your discoveries here

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

    I like the format.
    Typescript really is amazing.
    Not sure this kind of “meta programming” is applicable for most people, but it still really cool to see and understand how this stuff works.

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

    There is a big difference between what can be expressed in typescript and what should be expressed in typescript

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

    This is crazy and goooooooood! I'm tired of mapping every type manualy.

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

    Sounds like a great pick for library authors

  • @antonpieper
    @antonpieper Рік тому +12

    I also "found" this library two days ago when I researched for efficient type level arithmetics in typescript. The last few weeks I have been on a journey deep into the depths of typescript's type system and I gotta admit, it is pretty awesome. This way of inferring properties defined by later intersections however feels like wizardry

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

      I was doing the same thing-type-level arithmetic.

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

      Its very addictive. You could do this before just with generic types, but this library makes the process a lot more beginner-friendly

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

    Interesting. I've always sort of considered things like "Pick" and "Omit" and ReturnValue" to be sort of like type-level-functions. This seems to be taking that to the logical conclusion.
    Wonder though if it's a solution in want of a problem? The examples seem a bit contrived, especially the one where they just do a bunch of logic on types that can only contain a single value. (i.e. the 95 one).

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

      I was thinking the same thing. I’m struggling to see how this abstraction makes any difference in the real world. I also imagine types that are heavily nested using these primitives will lead to the TS chose of infinitely nested death.

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

      I felt the same way, the example shown in the video seemed really contrived, but it looked really intriguing and haskell-y. On the repo itself there is a much better example (the one with an accompanying video demo) where it's used to infer typed params from a URL, which seemed more practical to me. I don't know enough about typescript or use it in a way that would need that, but I could see it being useful to at least some library authors. Maybe even a lot of libraries!

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

      @@Quiqsave I mean I *did* have the idea that this could be used to implement a Monad library! monads are supposed to be higher order generics, i.e. something like Monad where M can take on the value of (for example) 'Promise'. But not 'Promise', just 'Promise' -- which you can't do in typescript because that's not a valid type (you can't do in most languages).
      Or at least I thought you couldn't do it in typescript. But this approach seems to blur the line between a fully instantiated type that can be used as a generic argument, and the generic itself.
      Which is very haskell-y. And very cute.
      Practical? Not so sure, but I suppose time will tell. My usual recommendation concerning Monads is to, whenever they come up in a conversation, just slowly back away :)

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

    Oh god, this is metaprogramming with C++ templates all over again!

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

    Looks like a debugging nightmare. LOL.

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

    I wonder how this would effect the performance of type checking if heavily used in a project. I already feel like type checking has mediocre performance in large projects, and can get horrendously slow if devs don't know what they're doing.

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

      There is no type checking in the runtime. The compile times may go up, but come on, who cares much about that?

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

      I assume he is referring to how feedback for LSP gets worse. In essence you IDE gets “slower”

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

      @@kasparpoland9803 Yes, I was referring to performance at compile time. By default, the type checker runs type checking on every keystroke. Even if this only takes 1-2 seconds, it can be very frustrating. I was just working on a TS project that took between 10-15 seconds for types to update *on every keystroke*. I found two types with a circular reference to each other (which is allowed, but a bad idea). After removing the circular reference, the time it took to run type checking dropped to under 500ms.
      There may not be performance implications at runtime, but slow type checking can make for terrible DX and create a tangible slowdown of development.

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

    "Your scientists were so preoccupied with whether or not they could, they didn't bother to think if they should..."

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

    I've been looking for a simple way to add HKT to Typescript like PureScript but most of the implementation provide not efficient enough as it always ended up that I needed to dig into the details. Hope that this is different. Thanks for sharing! And good work👍

  • @marzouguiomar9470
    @marzouguiomar9470 9 місяців тому

    is it a good idea to overide native javascipt api signature on global.d.ts with this librery to have a more accurate/restrictive type checking

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

    Looks cool, but I really hope they simplify the syntax more. Most of us even struggle with the most fundamental types of Typescript.

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

    I would love it for some of this in my codebase. But I know some that would probably put it on everything, and then some others will not know what to do during a feature request, because TS is giving all sort of error messages.

  • @user-gf9ri4wj5h
    @user-gf9ri4wj5h Рік тому +2

    Seems cool, but… where can we use it

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

    Great video Matt! TS just keep giving me Imposter syndrome. I feel like I have to learn these tricks/obscure things to be able to say I know TS

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

    Wondering if you would like the 'fp-ts' library, it is basically this but for javascript

  • @wfl-junior
    @wfl-junior Рік тому +2

    Can you bring a good useful use case?

  • @battatia
    @battatia Рік тому +6

    Wow this is really cool. Defo would be interested to see some real world applications but it's honestly already very neat just on its own terms

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

      That’s the amazing thing about typescript.
      For most people, “vanilla” typescript with a small bit of wizardry is all you need.
      But then there is this other layer of typescript magic that is just freaking cool, irrespective of if it is actually useful (currently) in, say, building react front ends

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

    The pipe operator is very similar to rxjs without the async aspect. I wonder if this pattern could improve the type chaining in that lib, or if they are already doing it.

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

      What I thought as well, looks like synchronous rxjs...it would be awesome if that was added to that library

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

    cool vid!

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

    Short videos like this are good, but I was waiting for you to compare writing the same type with and without the library. Even the library fails at the confirmation by not including `const a: res1 = 95` in the playground example, validating it in our brains.

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

      not true. The comment under the variable shows the type is 95

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

    Thanks

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

    Could you give some sort of practical application for this? I don't understand why you would want your typesystem to mutate numbers in a tuple for example.

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

    I mean, it looks intriguing, but I can't imagine what use I'd have for it.

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

    How does one step through debug this code? Newb question.

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

    I know a guy who created a Rust program that solves the 8 queens problem entirely at compile time using the type system. It'd be very interesting to see if libraries like HOTscript also make this possible in TS!

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

      I saw a blog post where someone did it in typescript as well a few weeks ago

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

    Please continue bringing us your revelations

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

    What is the extension that tells you the type with the comment // ^?

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

      ua-cam.com/video/u0adKDu--cA/v-deo.html

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

    I don't think I'll be able to use this at work. My collegues struggle with basic types. They can with some help use my custom generics. But if I throw something like this into the codebase it'll be a struggle.
    How is the performance of this? for my own projects I usually run trpc, and that's known to wreck ts-server.
    There's an infer in that higher order type, so my guess is, it's not too great if you overuse it.
    But definitely fascinating to say the least.

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

      Same here, my colleagues hardly understands the necessity of unit test and even less the needs of using types. But, you'll find it absolute necessary if you roll your own project, to speedup by replace most of the test using types, and scale in complexity

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

    feels like a new debugging nightmare

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

    So first you add typing to javascript to make it more readable, and then you take those types and make them into some weird object-pointers you pass around? I think I now understand what biologists mean when they say evolution is blind.

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

    I think.... The first example is doing something I've seen happen (kinda) in c++ I have no c++ experience at all but I've seen people string standard library functions together to perform complex operations. Either way it's giving Haskell vibes and in the case of tuples it seems very much like J K or APL

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

      Yeah this reminded me of some wizardry you can achieve with C++ templates and constexpr evaluation

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

    Hi Matt, I have a (maybe?) challenge for you. Trying to write a higher order React component whose resulting function takes a generic and forwards it to the passed component IF the component passed to the hoc takes one.
    const Result = withHoc(Comp);
    ...
    // no generic if not required by Comp
    // generic if required by Comp
    This is necessary when Comp's prop takes a callback that needs to pass Type back up to the parent rendering the Result.
    Have seen some janky examples, such as where Result is typecast to override the HOCs returned type, but it's never very clean. Maybe you can come up with a more semantic solution with some kind of "generic generic"

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

    I didn't know that I could pass an input to an interface

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

    nuts indeed

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

    And here I am still trying to create a Type to perform bitwise operations on static numbers. I don't think TS is powerful enough yet to be able to do this.

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

      I'm sure if you asked in my Discord we could figure it out.
      mattpocock.com/discord

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

    How does 'this extends" work in this case?

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

      this extends { infer Whatever } is a conditional type! And it's testing on the value of 'this', which is only available in interfaces. Pretty wild.

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

      @@mattpocockuk thanks, makes sense!

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

    jesus, as soon as I saw it, it's like, why didn't I think of that?! 🤦 That's awesome! 😆
    TypeScript has some pretty good built in ones like `Awaited`, but it's pretty odd there aren't more utility type libraries. Seems so obvious.

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

    I like the freewheeling style better.

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

    This means typescript has more responsibility rather than helping the developer understand their code. I hope it doesn't cause much confusion to new devs thinking what is typescript & it's role in the project. Personally, this looks really simple.

  • @11WicToR11
    @11WicToR11 Рік тому +3

    this feels like we finally went full round to "compiled language" ...this is "compilation step" where value is created during "typescript => js compilation" and baked in, costing some computation on developer PC but every client just uses it. We reinvented "static values" again?

  • @Chris-jm2gx
    @Chris-jm2gx Рік тому

    It's cool and all, but the question is how often are you gonna use this out in the wild? Probably never.

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

    I think my comment did not make it through. I implemented a version of this called free-types supporting type constraints, and it changes a lot of things. I encourage you to check it out. It has a a good readme and guide explaining how it works and the challenge of making it type safe.

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

    More freewheeling videos!

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

    Whoever created this library should have gotten mail from Hogwarts

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

    Doesn't it drain the battery just to calculate that monstrosity?

  • @user-un9cs7zq5w
    @user-un9cs7zq5w Рік тому

    Cool.

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

    It sounds a cool library for functional programming
    But I believe RxJs may able to do the similar things or even more
    (Since I am a bit familiar with reactive way)
    May I know any recommendations when to use hot script and when to use rxjs? 🙏

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

      They’re not even the same thing. Rxjs is a runtime thing and Hotscript is at the type level.

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

    Please do a whole video just on the different ways people hack TypeScript to allow for operations on numbers. I have no idea how you accomplish something like that without some crazy set-theoretic definition of a "number"

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

      You should clone HOTscript git. It is actually completely insane how they do power, addition, substraction and multiplication.

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

    Oh man, here we go again with HOC but in ts now. You guys remember how lovely HOC were in react? 😂. Jokes aside, might be not being smart enough or too simplistic but I think this pattern is so hard to read and reason about 😅.

  • @ahmed.systems
    @ahmed.systems Рік тому +13

    Putting logic in type definitions is probably the most blasphemous thing I've seen, since I switched from JS to TS

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

      It called typedriven development and mathematically proven to be better

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

      There's going to be a time and a place for code like this, for example this will be invaluable for library authors.

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

      ​@@WayOfTheCode the problem is that ts types don't exist at run time

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

    I cannot even imagine a use-case for this.
    I guess one use-case is for example making sure a list contains an exact value? Say you have a yearly budget and you want to make sure the sum is valid... All of which in TS directly?

    • @RD-eh3tz
      @RD-eh3tz Рік тому

      So you did imagine a use-case then?

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

      @@RD-eh3tz The thing is though, I don't know if this would work in that scenario

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

    Without an example is hard to grasp why it's intriguing or even useful.

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

    I love the idea of (pseudo)arbitrary code execution for the sake of accurate IntelliSense in scripting languages, but the syntax is weird and the performance on this is probably terrible 😬
    at this point typescript should just let you write type logic in a subset of javascript.

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

    Why Not fp-ts or effect-ts?both libs are way more powerfull than that..

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

    There's been a talk since forever about Higher Kinded Types in Typescript. This library is unfortunately not that. I can see some utility in this library though, the time will show.

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

    Damn I was thinking of making something like this 😮
    Lets make simple types like get method type, just simplyfying underlying typescript

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

    We are playing god.

  • @user-dr8kh8jp8p
    @user-dr8kh8jp8p 5 місяців тому

    Why do we need this?

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

    k but why?

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

    Its an interesting library. It feels more clever than useful, but I generally lack imagination :shrug:
    You should at least add a goatee or something to brand the more casual videos

  • @Frank-iz5ob
    @Frank-iz5ob Рік тому +2

    Man, F# was really far along all this time.

  • @PS-dp8yg
    @PS-dp8yg Рік тому

    Why can't you just use functions like pipe and compose to do function composition?
    const composition => method => (...fns) => initialValue => fns[method]((value, fn) => fn(value), initialValue)
    const compose = composition('reduceRight');
    const pipe = composition('reduce');

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

    This is akin to "ramda", but types and not JS operations. You REALLY should look into "ramda".

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

    The people that pioneered HKT techniques get no attention, but the author that wrote an attention grabbing library called "hotscript" gets all the attention. These days, programming is an attention game, you don't have to write something good or new, you only have to be the first to have your stuff mentioned by social media influencers. Why bother to write anything at all if you can be overshadowed by inferior solutions that play the attention game?

  • @SR-ti6jj
    @SR-ti6jj Рік тому

    I'm still waiting for cuckscript to drop

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

    Bro made the type system turning complete. In all seriousness, I feel like if you need to do this, you have bigger problems in your architecture.

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

      Excluding devs of very type-crazy libraries like Zod or prisma of course.

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

    convert typescript to javascript

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

    Reinventing JavaScript? Lol

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

    Starting to think Rust and WASM might just save frontenders from falling into this Typescript trap. Typescript is nice and I love it, but it’s getting to a point where it’s too clever for your own good.

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

    Ahh, very nice but so unnecessary :D

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

    Oh gosh C++ templates story repeated again

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

    has everyone who writes typescript ever heard of the KISS principle? This is a terrible, awful idea. The entire thing is just moving "business logic" to the type level from the function level, losing both any value gained from debugging tools and further increasing the opacity of code. Performance analysis and optimisation will be terrifying.

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

    i hate this

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

    Typescript is ruining javascript! this is just bonkers