This WILL CHANGE How You Work With Strings - Advanced TypeScript Magic!

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ม.ค. 2025

ความคิดเห็น • 47

  • @MrAlao675
    @MrAlao675 18 วันที่ผ่านมา +18

    you solve typescript types as if you don't know anything else... well done man.

    • @Typed-Rocks
      @Typed-Rocks  18 วันที่ผ่านมา +6

      Everyone needs a hobby 😝

  • @jfftck
    @jfftck 15 วันที่ผ่านมา +12

    Isn’t this getting outside the domain of types? I don’t understand why you would really want or need this, it is a lot of computation on something that should be a concrete type definition. This is bad practice for typing and I wouldn’t use this code in my code base, it’s also pointed out that runtime checks are necessary for any values that are not a constant.

    • @HelloWorld-rx1iy
      @HelloWorld-rx1iy 11 วันที่ผ่านมา

      yep, same! most of the stuff i (or we) deal with are dynamic data (eg: pulling out data from db / api(s)), so you can't leverage this in your projects

  • @LePhenixGD
    @LePhenixGD 18 วันที่ผ่านมา +6

    You never fail to amaze us ! This is wonderful !!!

    • @Typed-Rocks
      @Typed-Rocks  18 วันที่ผ่านมา +1

      Thank you so much for your kind words. Glad it is helpful ☺️🤘

  • @pierwszywolnynick
    @pierwszywolnynick 16 วันที่ผ่านมา +5

    very cool but as always - please don't actually use it, especially for comparing large numbers; you will kill the compiler and IDE performance quickly

  • @punithg1572
    @punithg1572 16 วันที่ผ่านมา +2

    This channel is just super fun! I’m super curious on how you come with these ideas though.

    • @Typed-Rocks
      @Typed-Rocks  16 วันที่ผ่านมา +1

      Thank you 😁, I like to fiddle around with the more unusual parts of languages so as soon as you start to do that, the ideas will come naturally 🤘

  • @BeeBeeEight
    @BeeBeeEight 18 วันที่ผ่านมา +1

    Amazing work there. I remember u covered how to make sure rgb values has exactly 3 numbers with template literals. Now I feel like trying with this method to make sure those numbers are within range (0-255).

    • @Typed-Rocks
      @Typed-Rocks  18 วันที่ผ่านมา +1

      You could but it could make your types quite recursively deep and not that well readable. So always keep that in mind 🤘👍

  • @danko95bgd
    @danko95bgd 18 วันที่ผ่านมา +5

    Wow typescript is so cool and powerful. Maybe it can tell me if func could throw an error, oh wait.

    • @Typed-Rocks
      @Typed-Rocks  18 วันที่ผ่านมา

      While I see your point, many languages think checked exceptions were a mistake. Often they just get thrown further.

    • @gerkim62
      @gerkim62 17 วันที่ผ่านมา

      This is the biggest issue in typescript by far

    • @pierwszywolnynick
      @pierwszywolnynick 16 วันที่ผ่านมา

      every function can throw an error, a stack overflow or out of memory, checked exceptions are just irritating

  • @KamelJabber1
    @KamelJabber1 16 วันที่ผ่านมา +1

    Fantastic content and we'll presented!

    • @Typed-Rocks
      @Typed-Rocks  15 วันที่ผ่านมา +1

      Thank you 😁

  • @mpcref
    @mpcref 13 วันที่ผ่านมา

    A nice use case for this would be defining JSON schema's which can be used to check JSON documents at compile-time using import. Here's a nice challenge for you: implement types for url's and emails. 😉

  • @precisionchoker
    @precisionchoker 18 วันที่ผ่านมา +2

    Wow this is awesome
    Subscribed

    • @Typed-Rocks
      @Typed-Rocks  18 วันที่ผ่านมา +1

      Awesome, thank you!

  • @benhaynes8869
    @benhaynes8869 13 วันที่ผ่านมา

    what is the extension/plugin/tools that displays the result when using ^?type? this looks very useful

    • @Typed-Rocks
      @Typed-Rocks  13 วันที่ผ่านมา +1

      It‘s called „twoslash-queries“ and it also exists for Jetbrains. There it‘s called „witt“

  • @aram5642
    @aram5642 14 วันที่ผ่านมา

    I don't think it will change the way I work with strings, because most of the strings I work with come from api and are not statically analyzable. But it is definitely a great lesson.

    • @Typed-Rocks
      @Typed-Rocks  13 วันที่ผ่านมา

      Thank you 🤘, I agree for that purpose it‘s not helpful.

  • @balaclava351
    @balaclava351 18 วันที่ผ่านมา +2

    Can you explain how to limit a number to range. Currently if I want to restrict a number to be `

    • @HelloWorld-rx1iy
      @HelloWorld-rx1iy 11 วันที่ผ่านมา

      you could use tuple types since they have fixed lengths, but i would be against stuff like this in real codebases since its gonna cost a lot of performance (and may error out for excessively deep instantiations)

  • @dave6012
    @dave6012 18 วันที่ผ่านมา +2

    I opening a PR with this type first thing monday morning

    • @Typed-Rocks
      @Typed-Rocks  18 วันที่ผ่านมา

      Keep me updated if they liked it 🤘😁

  • @djs-vids
    @djs-vids 17 วันที่ผ่านมา

    hihi! How do you view the result of the type as a comment like that (3:04)? You were using a different IDE before but not it's finally VSCode I think. Great content btw!

    • @Typed-Rocks
      @Typed-Rocks  17 วันที่ผ่านมา +2

      Thank you 🤘. It‘s called „twoslash-queries“ for vscode and „witt“ for Jetbrains.

  • @kuyugama
    @kuyugama 16 วันที่ผ่านมา +2

    There are no real usage for this

  • @ИльяСтрелец-ц4к
    @ИльяСтрелец-ц4к 18 วันที่ผ่านมา

    Think it's better to take string's "length" property directly, as it is readonly despite arrays length property which can be set directly by programmer

    • @Typed-Rocks
      @Typed-Rocks  18 วันที่ผ่านมา +2

      In types you can‘t use the length property of the string as it‘s just „string“. That‘s why you need to do that trick.

    • @kettenbach
      @kettenbach 15 วันที่ผ่านมา

      @@Typed-Rocksthis gives compile time support also. String.length is runtime

  • @moneyfr
    @moneyfr 18 วันที่ผ่านมา +3

    you should work with valibot

    • @Typed-Rocks
      @Typed-Rocks  18 วันที่ผ่านมา

      I will look into it. Looks interesting 👍🤘

  • @AbhiShake-pl3cf
    @AbhiShake-pl3cf 18 วันที่ผ่านมา

    Counter doesnt need to be an array. It should just be a readonly number

    • @Typed-Rocks
      @Typed-Rocks  18 วันที่ผ่านมา

      It cant, as we need to update the counter every recursive iteration. Otherwise we would need to create an array and increment it and put it back into a number each time.

    • @AbhiShake-pl3cf
      @AbhiShake-pl3cf 18 วันที่ผ่านมา

      Ah yes i just tried and i cant just increment numeric type. Sorry for saying that without confirming it. You are awesome

    • @Typed-Rocks
      @Typed-Rocks  18 วันที่ผ่านมา

      @ no worries. Thanks for your comment 😁

  • @snatvb
    @snatvb 18 วันที่ผ่านมา

    it would be great to have possibility to add own error messages :)

    • @Typed-Rocks
      @Typed-Rocks  18 วันที่ผ่านมา

      We could make it so that instead of never, it returns an object type with an error property in

    • @snatvb
      @snatvb 18 วันที่ผ่านมา

      @@Typed-Rocks but it's not an really error. I mean improvement TS compiler :) but it's just kinda my "ny wish" :D

    • @HelloWorld-rx1iy
      @HelloWorld-rx1iy 11 วันที่ผ่านมา

      @@snatvb you might as well make an eslint rule for that lol (assuming smth like this doesnt exist, i am not well versed into the rules)

  • @mjerez6029
    @mjerez6029 13 วันที่ผ่านมา

    This is neat trick but wouldn't use it, pretty sure Typescript checker will degrade pretty quick if code start to be crowded with there kind of tricks. Impressive none the less.

    • @Typed-Rocks
      @Typed-Rocks  13 วันที่ผ่านมา

      The typechecker is quite good in caching this stuff. But of course only use it if you have a usecase 👍