No More Unreadable Types! A Cleaner, Functional Way to Build TypeScript Types

No More Unreadable Types! A Cleaner, Functional Way to Build TypeScript Types

Typed Rocks

3 месяца назад

6,462 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@mrcavas
@mrcavas - 20.12.2024 20:58

looks interesting, gotta give it a try

Ответить
@royz_1
@royz_1 - 20.12.2024 21:16

This looks amazing!!

Ответить
@_jam1eK
@_jam1eK - 20.12.2024 21:17

i think it should be official feature. ternary ops is disgusting.

Ответить
@moneyfr
@moneyfr - 20.12.2024 23:01

Amazing

Ответить
@dave6012
@dave6012 - 20.12.2024 23:18

Can you also fix the “this ridiculously complex and nested object type has some minute error but I’m only going to show you the first 100 lines of the error which doesn’t show the actual error because it’s 200 lines”? Because that would be great 😂

I get the “type <entire western literature with a typo> is not assignable to type <entire western literature>” but it’s just a wall of truncated red text 😢

Ответить
@zayne-sarutobi
@zayne-sarutobi - 21.12.2024 00:14

God bless you for this man, would really aid my creativity when solving type problems

Ответить
@Mohamed.ibn.Alabbas
@Mohamed.ibn.Alabbas - 21.12.2024 00:30

That’s why I like zig meta programming

Ответить
@dabneeboy
@dabneeboy - 21.12.2024 00:57

wow, this seems really nice!

Ответить
@XCanG
@XCanG - 21.12.2024 01:25

In my case I don't use nesting like that, but instead I use () brackets to group types. While it does not change anything meaningful, it make it readable to me.

Ответить
@w01dnick
@w01dnick - 21.12.2024 02:01

Some illogical step, that you define type as function, but use it still with angle brackets, not like function call.

Ответить
@verdaderoken
@verdaderoken - 21.12.2024 02:17

What a hidden gem this is. Thank you

Ответить
@backhdlp
@backhdlp - 21.12.2024 02:53

can this do anything other than if/else branches? variables maybe? switch statements would be cool.
because avoiding ternaries by writing a whole meta language just feels like working around the problem instead of fixing it.
i understand where youre coming from, ternaries were never meant to be chained a lot, so the problem lies mostly in the language design of typescript itself, tho in that position i would try to reconsider how i write my types, or better yet choose a language with a reasonable type system that wasnt hacked on another without one
tbf i have the luck of not being a typescript developer, im sure there are valid reasons youre masochistic

Ответить
@taquanminhlong
@taquanminhlong - 21.12.2024 04:53

Definitely a great spell for ts wizard 😂

Ответить
@namhoang5550
@namhoang5550 - 21.12.2024 04:58

You are a god, thank a lot!

Ответить
@a-yon_n
@a-yon_n - 21.12.2024 05:01

Amazing thing, a suggestion though, can we write it like this instead:

functype Find<T> {}

That way it’s more consistant between the definition and the call, and is compatible with the current TypeScript syntax.

And can you make a proposal to the TypeScript team to add such a feature to the TypeScript itself?

Ответить
@fenryrtheshaman
@fenryrtheshaman - 21.12.2024 05:45

I was excited when I thought this might enable passing generics without arguments to other generic to use within. I don't really like the if/else chain either, but to each their own there.

I think TypeScript would benefit from a terse pattern matching syntax.

Ответить
@BeeBeeEight
@BeeBeeEight - 21.12.2024 07:12

This is the kind of type that Microsoft should have created in the beginning, but never did. I like TS but always hated that it can only use nested ternaries to express switch cases. At least with this type buddy, the syntax looks so much cleaner. Thank you so much! 😊

Ответить
@lillllliiill-r3e
@lillllliiill-r3e - 21.12.2024 07:40

really like the idea. maybe typescript team can add a new keyword "typefunction" which dev can write a type function.

typefunction Maybe(T) { if (T extends string) return string; else return T; }

Ответить
@jerondiovis6128
@jerondiovis6128 - 21.12.2024 12:40

I would even pay to have this plugin for Webstorm too.

Ответить
@pwall
@pwall - 21.12.2024 13:02

The outfile should probably be .ts not .d.ts

Ответить
@karamuto1565
@karamuto1565 - 21.12.2024 14:03

This is actually a great idea. Will try the web version after my holiday vacation.

Question: would it be possible for you to abstract the "infer" syntax with something of your own? Like "getInnerType" or something. I see people always having problems with the "extends" in combination with "infer" all the time.

Ответить
@snatvb
@snatvb - 21.12.2024 15:06

I've been wondering every time why there's no way to write types like normal functions, and here it is!

Ответить
@r0den
@r0den - 21.12.2024 15:27

Buds, can we all agree thats should work in .ts files without any IDE extensions? I'm thinking of a babel plugin to do it in the background, what do u think?

Ответить
@TheCoonHouse
@TheCoonHouse - 21.12.2024 16:14

Great plugin! Thanks.

Would it be possible to remove de "tb" from the .d.ts filename?
Like typebuddy.tb -> typebuddy.d.ts

Ответить
@gustavoshigueo
@gustavoshigueo - 21.12.2024 18:11

This is a minor and stupid nitpick, so feel free to ignore it, but can you add a space between the word "if" and the opening parenthesis? It's triggering my OCD lol

Ответить
@j0code
@j0code - 22.12.2024 01:15

I think creating d.ts is not ideal since d.ts types are global

Ответить
@annamuller4730
@annamuller4730 - 22.12.2024 05:09

just a note. writing Find<Inner> or StringOrNever<A> in typebuddy is somehow wrong. you should use normal brackets like Find(Inner) or StringOrNever(A) especially since that is how you define the type itself in your first line. makes no sense to use () there and then use <> later on. bad syntax.

beside of that good idea

Ответить
@ThiagoOliveiraSantosfaren
@ThiagoOliveiraSantosfaren - 22.12.2024 17:13

Wow This is an instant must have plugin. Thank you very much!

Ответить
@zul.overflow
@zul.overflow - 26.12.2024 19:02

awesome!! 👍👍

Ответить
@_heyMP
@_heyMP - 27.12.2024 16:29

Just casually drops the plugin of the year like it's nothing. 😂

Ответить
@AbhiShake-pl3cf
@AbhiShake-pl3cf - 02.01.2025 16:55

After watching your last video (which was my first video that i watched from you), i was like "finally, someone who knows more typescript than me". I have read and learned alot from tanners code before. Will binge watch all your videos and read your repos now. Yay. Thanks so much for such content man. The more i watch you, the more i think "man this guy is incredible". This is a simple parser to implement but such a genius idea

Ответить
@glazevolda823
@glazevolda823 - 24.01.2025 00:33

Thank you for cool & useful thing! It would be interesting to see how you made the plugin for the ide, and how you compile of types to functions and back. It would be interesting to see a video about this. Thanks again!

Ответить
@vhxnyu1
@vhxnyu1 - 28.01.2025 22:46

good

Ответить
@tonitabak
@tonitabak - 15.02.2025 20:10

Bro, your channel is gold mine <3

Ответить
@Noam-Bahar
@Noam-Bahar - 28.02.2025 02:58

Neat

Ответить
@chaquator
@chaquator - 08.03.2025 23:42

great work. one thing which would be neat is incorporating various loops or mapped types as for loops or some fluent mapping function on a union of string literals (e.g. keyof T)

Ответить