Пікірлер
@floofyjr
@floofyjr 22 күн бұрын
The worst tutorial i've ever seen
@rahul38474
@rahul38474 28 күн бұрын
I did something similar for another project, I made K extends string the outermost ternary operation so that in the true branch I didn’t need to do K & string, as in that branch K is narrowed to some string type. I used this type (I called it dot path) to map keys of one type to keys of another type based on a suffix in each key. Type level programming is my favorite feature of TypeScript (also probably the only feature I like tbh) because it feels like doing a proof, and also because the literal types make for a really good developer experience since the LSP can suggest strings from that type.
@nestnik
@nestnik Ай бұрын
That's amazing! What resources can I use to level up my type-level programming skills?
@coolemur976
@coolemur976 2 ай бұрын
All of that just to have some intellisence on (string): string 😁
@maximemondello6174
@maximemondello6174 2 ай бұрын
This video is Amazing ! I needed a lite translation hook for my project and didn't want to fiddle with libraries for it. This is just perfect! I adapted it to be able to loop trough several files of translate keys and it works wonderfully ! Thank you for that!
@kyleshrader9053
@kyleshrader9053 3 ай бұрын
use vscode terminal T_T
@EconomicsDomain
@EconomicsDomain 3 ай бұрын
Great explanations, but personally would frown if I saw this in a project. Mental gymnastics and cognitive overload ;)
@TheTom265
@TheTom265 5 ай бұрын
Brilliant. Thank you!!
@dawid_dahl
@dawid_dahl 5 ай бұрын
This is starting to look like Haskell code, haha.
@Athet0s1s
@Athet0s1s 5 ай бұрын
I actually used this in our company to name the fields in the api responses as we get Keys that are in objects or arrays, and we use them parsed in a specific way (with __ instead of .) and It was so difficult for me to manage to do this. I think this is greatly explained and would've been so Happy to find this video when I did this 😂
@tezismith8795
@tezismith8795 5 ай бұрын
great explanation! I didn't know about that `K & string` trick, very useful :) thanks
@weroro
@weroro 6 ай бұрын
7:37 It only works on Unix systems (Linux, Mac OS) and it doesn't work on Windows. The universal solution is to use the rimraf library.
@user-dz6il2bx5p70
@user-dz6il2bx5p70 7 ай бұрын
That's some next level dogshit, ngl.
@blazed-space
@blazed-space 9 ай бұрын
Please more content like this, I am engaged in building libraries for my websites and client sites, always running into brick walls over design patterns as it is hard to track down quality lessons for this kind of stuff
@zak-kepler
@zak-kepler 9 ай бұрын
Very interesting, thanks
@Douwab
@Douwab Жыл бұрын
Excellent video! This is simple and clear, exactly what i was looking for. I just subbed to your channel and i am waiting for more videos like this one!!
@LewisCowles
@LewisCowles Жыл бұрын
Why didn't OP just define types to lie about how EventEmitter works, to get the same benefits?
@user-jg7rg2ni7h
@user-jg7rg2ni7h Жыл бұрын
Yeah, ok this is really bad. You need to pick up event patterns from different languages rather than what you are doing. this is simply just bad code created from a very corky js community. Define your events as classes and stop separating the event type from the payload. This is just bad.
@enjay86
@enjay86 Жыл бұрын
au, my brain!
@webbae
@webbae Жыл бұрын
Great rundown thanks Simon.
@allmeadow1899
@allmeadow1899 Жыл бұрын
Great 👏 thanks!
@voyager_ll
@voyager_ll Жыл бұрын
Wow, that's crazy :D didn't know that was possible!
@disel920
@disel920 Жыл бұрын
Cool, my version without `& string` const data = { env: { name: "", payload: { price: 0, size: 0, }, }, }; type DataType = typeof data; type PathsInRecord<OBJ extends Record<string, any>> = keyof { [KEY in keyof OBJ as OBJ[KEY] extends object ? KEY extends string | number ? PathsInRecord<OBJ[KEY]> extends string ? KEY | `${KEY}.${PathsInRecord<OBJ[KEY]>}` : never : never : KEY]: never; }; type res = PathsInRecord<DataType>; const a: res = "env"; const a0: res = "env.name"; const a1: res = "env.payload"; const a2: res = "env.payload.price";
@GabrielSoldani
@GabrielSoldani Жыл бұрын
I tried this with SendGrid instead of Mailgun, and the main problem with it was that my messages would always end up classified as Promotions on Gmail users’ accounts. It was enough to convince me that, to guarantee mail delivery and correct classification, it’s probably not a good idea to use SMTP servers aimed at promotional or automated use for my personal messages.
@sstur
@sstur Жыл бұрын
Yes, this is particularly a problem with Sendgrid, because a lot of their users send marketing and spam using that service. Mailgun is somewhat better, and Mandrill is the best in my experience, about getting through to people's inbox. These services are supposed to be used only for transactional email and not marketing or newsletters, but it doesn't always work out that way.
@FrancoisBothaZA
@FrancoisBothaZA Жыл бұрын
So glad to have discovered this channel. I'm fairly new to Typescript and I'm just overwhelmed with all the options and module types and and and... Thanks for helping with this concise explanation. More on modules would be great.
@dimitrisqq
@dimitrisqq Жыл бұрын
Finally. Thank you!
@confused_horse
@confused_horse Жыл бұрын
I was casually watching this in the living room and was really excited because it's just extraordinarily good content. But as soon as I was done I turned around to see my girl friend judging me. She called me a nerd and now I am happy in two ways. :> Thank you for sharing this and "yolo"
@trongvinhnguyen6366
@trongvinhnguyen6366 Жыл бұрын
I have though about this many times and though it was impossible in TS. Now you've clear my mind. Thank you!
@Giffeln
@Giffeln Жыл бұрын
Great video! My version for this case would be type PathTo<T extends Record<string, unknown>> = keyof { [K in keyof T as T[K] extends Record<string, unknown> ? `${K & string}.${PathTo<T[K]> & string}` : K & string]: any; };
@daniellynch3724
@daniellynch3724 Жыл бұрын
This is amazing black magic and I’m glad I watched the video. If I ever saw anyone submit anything remotely similar to this in a PR it would get a Deny so fast my left click would break the sound barrier.
@LeshkaSaD
@LeshkaSaD Жыл бұрын
very educational video 👍 would be great to see more videos about complex types in TS and you find a solution for them
@RedStone576
@RedStone576 Жыл бұрын
neat!, now im gonna yoink this
@76Freeman
@76Freeman Жыл бұрын
Man, I've just discovered your channel, this is the 3rd video I've watched and all your videos are little gold nuggets :D I love your content.
@76Freeman
@76Freeman Жыл бұрын
Once again, great video. One question though, you've mentioned that the two most important options are "strict": true; and "noUncheckedIndexedAccess": true,. How about option "strictNullChecks"? This one should be pretty important too no?
@sstur
@sstur Жыл бұрын
Right. Turning on `strict: true` will enable "all of the strict mode family options" which includes strictNullChecks and a bunch more. Details here: www.typescriptlang.org/tsconfig#strict
@76Freeman
@76Freeman Жыл бұрын
Wow great stuff. You've just gained a new subscriber :). I've been getting more and more into Typescript and I often struggle with recursion. I think the "variables" name in types aren't always the best :) things like K and T aren't very descriptive and it makes it really hard to understand what is going on :). I think one nice thing would be to comment the most challenging parts so you know what is going on. But I loved your process though, thank you very much the great video.
@dokkenrox
@dokkenrox Жыл бұрын
Man, that's rough! LOL It's an elegant solution but it's not very legible. It seems like once we get to the level of complexity where we need to invoke the term "type-level programming" that Typescript's terse syntax doesn't always let you express things in a way that's suitable for maintainability. You see the same kind of shortcomings with complex regular expressions. It starts to feel like you would almost want an extended syntax to deal with that sort of thing. Some languages actually do have alternative ways to build regexes that are more verbose but easier to read. Maybe MS will do something similar for Typescript in the future.
@vovasava3498
@vovasava3498 Жыл бұрын
_.get()
@InMemoryOfNeo
@InMemoryOfNeo Жыл бұрын
Awesome 👌👏👏👏👏👏👏👏👏
@shaikhdanish2793
@shaikhdanish2793 Жыл бұрын
Can we also program the object?
@alextrofimov8320
@alextrofimov8320 Жыл бұрын
Why do you need to do ": keyof. { [K in EXP]: any } "instead of ": EXP"?
@coffeeandbytes9854
@coffeeandbytes9854 Жыл бұрын
This is my issue with TypeScript tutorials, there are only two skill levels being taught: Absolute Beginner or Dark Wizard.
@sstur
@sstur Жыл бұрын
NOTE: It was unclear in the video (and unclear on their pricing page) but Mailgun DOES still have a free tier called the "Flex" plan. You have to start with a free trial and then downgrade to the Flex plan. Some details here: help.mailgun.com/hc/en-us/articles/203068914-What-Are-the-Differences-Between-the-Free-and-Flex-Plans- For a full list of mail providers that offer free options, see here: bit.ly/uptlepp
@MinorMood
@MinorMood Жыл бұрын
Man, very good, thanks for sharing! With the TS one actually have a huge boilerplate even before actually start coding - but it is definitely worth of that!
@sstur
@sstur Жыл бұрын
The code from this video can be found here: bit.ly/owqekjr
@nazaka9904
@nazaka9904 Жыл бұрын
i see it right on the next day after doing exactly the same :)
@eltyo340
@eltyo340 Жыл бұрын
14:00 I'm glad I'm not the only one who writes "yolo" when writing dummy data/console logs
@0xramon
@0xramon Жыл бұрын
been playing around with something similar, ended up with type DotNotation<T> = { [K in keyof T]: T[K] extends object ? `${K & string}.${DotNotation<T[K]>}` : K & string; }[keyof T]; type Foo = DotNotation<typeof my_obj>
@0xramon
@0xramon Жыл бұрын
can also extend it to filter out certain keys, for example ``` type Excluded = "sample" | "other"; type DotNotation<T> = { [K in keyof T]: T[K] extends object ? `${K & string}.${DotNotation<T[K]>}` : `${K extends Excluded ? never : K & string}`; }[keyof T]; const x = { foo: "a", sample: "unreachable", bar: { other: "unreachable", zoo: "b", moo: "c", }, }; type Foo = DotNotation<typeof x>; ``` only `"foo", "bar.zoo", "bar.moo"` are available
@sstur
@sstur Жыл бұрын
The code from this video can be found here: bit.ly/iuebsku
@freespeech515
@freespeech515 Жыл бұрын
type script sucks for front end
@MaximeTrichard
@MaximeTrichard Жыл бұрын
How would you also allow "hello.greetings" for instance ? (stop the type mid-path) It can sometimes be useful, although this is not the case in your example obviously. Anyways, great explanation, thank you for that !
@seftikara651
@seftikara651 Жыл бұрын
you could change the ``` T[K] extends Record<string, any> ? `${K & string}.${Keywords<T[K]> & string}` ``` part to ``` T[K] extends Record<string, any> ? `${K & string}.${Keywords<T[K]> & string}` | K ``` the ```| K``` here inserts the bare(?) type along with the nested type. (unification) the complete one would look like this ``` type Keywords<T extends Record<string, any>> = keyof { [K in keyof T as T[K] extends string ? K : T[K] extends Record<string, any> ? `${K & string}.${Keywords<T[K]> & string}` | K : never]: any; }; ``` **I changed PathInto to Keywords btw, fits better for me
@ionitaa
@ionitaa Жыл бұрын
Imagine geting hired somewhere and your first task is to debug this while Simon is no longer working there
@sstur
@sstur Жыл бұрын
😂 You've legit got a point here