Typescript Mistakes Every Junior Developer should Avoid | clean-code

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.ย. 2024

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

  • @FozIrenics
    @FozIrenics ปีที่แล้ว +64

    The most concise explanation of `unknown` vs `any` i know of:
    - `unknown` is the union of every type there is.
    - `any` is the "elastic" type which fits to what it needs to be. (It may also be thought of as the switch to selectively disable type checking)
    bonus point: `never` is the union of no type.

    • @tylim88
      @tylim88 ปีที่แล้ว +2

      And when you realize unknown is a complementary type of never

    • @Microphunktv-jb3kj
      @Microphunktv-jb3kj ปีที่แล้ว

      i would add, that use const enum, not enum... it will make optimization better ; )

    • @AmodeusR
      @AmodeusR ปีที่แล้ว

      And what a "no type" would be?

    • @unknownguywholovespizza
      @unknownguywholovespizza 11 หลายเดือนก่อน

      ​@Winter_Wyvern1are you using it by now?

  • @arjix8738
    @arjix8738 ปีที่แล้ว +156

    Look, using enums does not make you a junior dev.
    Enums don't make you anything.
    And also, yes you can directly pass a number instead of the enum, but that defeats the purpose of enums in the first place.
    The "junior mistake" is not using enums, but passing the enum value directly instead of using the enum.
    Do you see the pattern?
    Using enums is not bad.
    Using enums the wrong way is bad.
    I've noticed that a lot of self proclaimed typescript experts on TH-cam talk badly about enums.
    But that just proves that you are junior devs yourselves.
    Don't blame a language feature, when you misuse it...

    • @unfilledflag
      @unfilledflag ปีที่แล้ว +19

      This is a guy who creates a union type and calls it an intersection pipe, so take it with a grain of salt.
      Enums are bad for other reasons, though: every other feature in TS can be just stripped away because they only exist as compile-time validation. Enums, on the other hand, generate code (an object to perform the map between names and values).

    • @climatechangedoesntbargain9140
      @climatechangedoesntbargain9140 ปีที่แล้ว +4

      though TypeScript still could improve enums - just passing a number shouldn't be possible.
      "Don't blame a language feature, when you misuse it..."
      sounds like C vs Rust, who blames the programmer when does make a mistake that's made easy by the language

    • @artistry7919
      @artistry7919 ปีที่แล้ว +1

      ts enum is actually bad compared to other languages, since it doesn't validate type the way you would expect ts or any other compiler to. You should use "object as const" instead of enum in ts because it works more like a proper enum

    • @tylim88
      @tylim88 ปีที่แล้ว +2

      Too much overhead using enum, it is not possible to generate new enum type out of a old enum type because enum is also a runtime code which is not manipulate able on type level

    • @jeffnikelson5824
      @jeffnikelson5824 ปีที่แล้ว +3

      enums should not exist in ts

  • @Mitsunee_
    @Mitsunee_ ปีที่แล้ว +3

    Not using satisfies is barely a Junior Dev mistake. It literally got introduced in the latest release of TypeScript and thus does not yet work in any of my projects. Also obligatory comment about how every youtuber bashes enums because it's the cool things to do and ignores the existence of `const enum` which literally fixes 95% of issues related to enums.

  • @joenewton251
    @joenewton251 ปีที่แล้ว +36

    I agree that you don't want to use "any" but if you are a junior dev then you probably don't want to use "unknown" either. Chances are very high that you know what type or types are a possibility at compile time. In this case, instead of returning "unknown[]" the fetch should return "(IAdminUser | IUser)[]" or even just "IUser[]" and then check if the user is admin and cast to admin at that time.

    • @atnguyenucchi9776
      @atnguyenucchi9776 9 หลายเดือนก่อน +2

      how about type of error in try catch. Are you use any

    • @RmonikMusic
      @RmonikMusic 8 หลายเดือนก่อน +1

      aside from catching errors and writing libraries or packages, I can't think of many scenario's where unknown would be good if you wrote your code properly.

    • @PlerbyMcFlerb
      @PlerbyMcFlerb 7 หลายเดือนก่อน +1

      @@RmonikMusic If you're using some third party lib or web api you don't particularly trust, it can be a good idea.

  • @harag9
    @harag9 10 หลายเดือนก่อน +9

    #4 - enums, I understand what your saying about using number enums, but if you misspell one of them and want to rename it, VScode would change it throughout your app. however for "GoodState" and using strings |string |string, if you change the string of the first one, then I don't believe VScode will update the string everywhere.

  • @ibgib
    @ibgib ปีที่แล้ว +11

    Great video! The first point at 1:00 does a great job on type guards, but doesn't really explain `any` vs `unknown`. Like at 5:03, code completion has nothing to do with `any` vs `unknown` and everything to do with the type guard. What `unknown` does a great job with is *requiring* that the narrowing happens before assignment. IOW if you change the code to use `any`, it will still work and the type guard will still allow completion. But it will fail to compile if you try to assign the unknown response to a user variable (whether admin or not) before that type guard.
    Just paste in the following in the typescript playground:
    interface IUser {
    id: number;
    name: string;
    foo: (s: string) => void;
    }
    /**
    * type guard would be better implemented like stated in the video, using `unknown` type.
    */
    function isUser(obj: any): obj is IUser {
    // extremely naive checking here for illustrative purposes only
    if (typeof obj === "object" &&
    typeof obj.name === "string" &&
    typeof obj.id === "number" &&
    typeof obj.foo === 'function') {
    return true;
    } else {
    return false;
    }
    }
    const obj = {
    id: 42,
    name: "Alice",
    foo: (s: string) => { console.log('foo: ' + s); }
    }
    obj.foo('const obj'); // compiles because tsc knows of the property on the object itself
    const anyObjDeserialized: any = JSON.parse(JSON.stringify(obj));
    const unknownObjDeserialized: unknown = JSON.parse(JSON.stringify(obj));
    // anyObjDeserialized. // no type completion because type `any`
    // anyObjDeserialized.foo(); // compiles but UNSAFE because we haven't narrowed the deserialized object.
    // (This actually throws at runtime because you can't deserialize functions like this.)
    // unknownObjDeserialized. // also no type completion because type `unknown`
    // unknownObjDeserialized.foo(); // unlike `any`, this SAFELY fails to compile
    let user: IUser;
    user = anyObjDeserialized; // compiles UNSAFELY because it's type `any`
    // user = unknownObjDeserialized; // SAFELY fails to compile, because it hasn't been narrowed
    if (isUser(obj)) {
    obj.foo('narrowed const obj')
    }
    if (isUser(anyObjDeserialized)) {
    // anyObjDeserialized. // YES code completion because of type guard
    anyObjDeserialized.foo('narrowed any');
    } else {
    console.log('type guard worked! deserialized `any` isn\'t a user (because foo fn deserialized isn\'t a function');
    }
    if (isUser(unknownObjDeserialized)) {
    // unknownObjDeserialized. // YES code completion because of type guard
    unknownObjDeserialized.foo('narrowed unknown')
    user = unknownObjDeserialized; // compiles because we have narrowed the unknown with the type guard
    } else {
    console.log('type guard worked! deserialized `unknown` isn\'t a user (because foo fn deserialized isn\'t a function');
    }

  • @abdulazeez.98
    @abdulazeez.98 ปีที่แล้ว +8

    Awesome tips!
    I have been working with typescript for few weeks, almost all pf the tips you mentioned I needed them at some point.

  • @martinemanuel8239
    @martinemanuel8239 ปีที่แล้ว +5

    All explanations were clearly and consistent, with perfect examples

  • @aminroslan
    @aminroslan ปีที่แล้ว +10

    Good stuff man. Been in the field for 4 years. Ive only known half of the things u mentioned. Awesome to learn something new today 😄

  • @ZeldriFR
    @ZeldriFR ปีที่แล้ว +22

    12:49 Fun thing is here, using satisfies keyword along with Record would be a good idea too, because for the red property, without satisfies (so color: Record = {} ) you will only have the common methods/properties between arrays and string, such as .length etc ...
    I'm pretty sure I saw this exemple in the documentation for satisfied :D

  • @AeroSW
    @AeroSW 9 หลายเดือนก่อน +1

    Learnt some new features that Typescript has that I wasn't aware of. The `satisfies` and `obj is Type` sections were nice to see. I've been using Typescript for 4 years, and never knew these existed, though, they may have been added more recently than my knowledge extends to (TS 2.4). I'm currently between jobs, so I'm taking my free time to catch up on technologies that I learnt prior to my most recent job.

  • @kajacx
    @kajacx ปีที่แล้ว +40

    The "isAdminUser" method should take "IUser", not "unknown". If you are worried that you will not get an IUser from your endpoint, use something like zod.

    • @hups6648
      @hups6648 ปีที่แล้ว

      Or ajv / any other type validator

    • @van_valdis
      @van_valdis ปีที่แล้ว +2

      @@hups6648 I used ajv and moved to zod in typescript context because zod's feature to get type from schema is a game changer for me.

    • @Friskni
      @Friskni ปีที่แล้ว +4

      isAdminUser should take an union type of IUser | IAdminUser and then the type guard can get to work. Using unknown is lazy imho and its not like it will give you any advantage at runtime.

    • @kajacx
      @kajacx ปีที่แล้ว +3

      @@Friskni IAdminUser is a subtype of IUser, so "IUser | IAdminUser" is the same as "IUser". I guess the latter is more clear on one hand, but also less clear on the hand, because it makes it look like it is not a subtype.

    • @vaibhav5783
      @vaibhav5783 ปีที่แล้ว

      @WyvernABCThats why most of the developer hates js and its libraries.

  • @Niconelli12
    @Niconelli12 ปีที่แล้ว +8

    5:00 - There is no need to actually use 'unknown' in this example, I think it would be more correct to use the following syntax:
    const goodUser: IUser | IUserAdmin = await response.json()
    Now you explicitly defined the possible types (interfaces) without being too "generic" with unknown.
    You can also define an "error" type/interface, let's say "IError", and use a type guard "isIError()". Then:
    const goodUser: IUser | IUserAdmin | IError = await response.json()

  • @rodrigolaporte274
    @rodrigolaporte274 ปีที่แล้ว +1

    This is pure gold. So clear and concise! Thank you!

  • @wensmartsandy
    @wensmartsandy 10 หลายเดือนก่อน +1

    I used to make these mistakes 5 years ago. Thanks

  • @jonathan-._.-
    @jonathan-._.- ปีที่แล้ว +1

    title recommendation: "typescript mistakes every junior should make at least once"

  • @patricsteiner8483
    @patricsteiner8483 ปีที่แล้ว +14

    4:17 why not assign IUser and then use the isAdminUser to make it more specific?

    • @unfilledflag
      @unfilledflag ปีที่แล้ว +2

      If you create a good validation function you can use it to detect errors. Suppose the `fetch` call might return either an user or an error message (or the API might change because APIs change).

  • @oscargm1979
    @oscargm1979 8 หลายเดือนก่อน +1

    I didn't know the thirs one, super interesting letting typescript to infer the type. Memoizing it😊

  • @ayo.bakare
    @ayo.bakare ปีที่แล้ว +4

    Great video, well explained… for all audience, I believe it will be easier to follow the examples if they are very bare or well slimmed down if you’re talking about the basics.

  • @emcpadden
    @emcpadden ปีที่แล้ว +1

    This is great!!! I've been using typescript for a long time and learned something. Thank you!!

  • @RealHomeboy
    @RealHomeboy ปีที่แล้ว +3

    Nothing of this makes you a senior dev. It takes so much more

  • @warenarapocgador4633
    @warenarapocgador4633 9 หลายเดือนก่อน

    Thank you so much this tip will adjust my type annotation in correct way to avoid using explicit any type

  • @lancetv4826
    @lancetv4826 6 หลายเดือนก่อน

    `satisfies` Operator is indeed awesome. Thank you for the tips, I learned a lot!

  • @AlainBoudard
    @AlainBoudard ปีที่แล้ว

    Some tips I knew but would not have been able to explain better than you ! Excellent video.

  • @lin-zchang4774
    @lin-zchang4774 ปีที่แล้ว +1

    This was great, I learned so much in this video. Thank you!

  • @milan5131
    @milan5131 ปีที่แล้ว +1

    11:04 type on line 18 for enum on line 19. There is cool trick, you can auto generate type for enums. It can be for instance `type GoodStateType = keyof typeof GoodState` - GoodState is enum name

  • @ryanvarley2391
    @ryanvarley2391 ปีที่แล้ว

    Mate this is so good! Definitely helped out this JS dev!

  • @maltehecht1845
    @maltehecht1845 ปีที่แล้ว +4

    Nice Tipps 👌
    If I'm not totally wrong, you're confusing intersection (& operator) and union (| operator).

    • @AlainBoudard
      @AlainBoudard ปีที่แล้ว

      Oh that's what I noticed but wasn't sure about !

  • @michaelash8552
    @michaelash8552 ปีที่แล้ว +2

    I am not a Typescript fan. I don't hate it but I definitely don't love it. Stuff like this is why. This is all very helpful but that aside from the unknown types and enums most of this doesn't pop up in other tutorials and training. Granted some are recent features but you have to be deep in the weeds of Typescript and frankly I've personally seen no significate benefits using Typescript that's made me want to take such a deep dive. I don't mind learning new things but I was doing fine without it.

  • @AhmadNasriya
    @AhmadNasriya 4 หลายเดือนก่อน

    I'm super new to TypeScript, but I use all the tips you just mentioned. Does that make me a senior developer?

  • @gro967
    @gro967 4 วันที่ผ่านมา

    Also a best practice is NOT prefixing Interfaces with I...

  • @mikaelberg4304
    @mikaelberg4304 ปีที่แล้ว +5

    Appreciate the tips and the video.
    Some constructive criticism: Take a breath once in a while (or don't edit video so it feels like you don't) There really isn't much time for the viewer to absorb your points before you are half way into your next one ;)
    Otherwise good video. Plenty of self-taught mistake patterns in web-development, nice to know what to look out for :)

  • @CodingElf
    @CodingElf ปีที่แล้ว

    thanks for this TypeScript tutorial. Love Typescript!

    • @CoderOne
      @CoderOne  ปีที่แล้ว +1

      Thanks! Keep up with making videos. They look great!

  • @mike110111
    @mike110111 ปีที่แล้ว

    thanks for this video, it was very informative. i don't like the idea of the custom type guard functions, they introduce possible runtime errors since you could write the wrong logic to determine the type, so i think they should be avoided when possible.

  • @shakapaker
    @shakapaker ปีที่แล้ว +223

    My recomendation not use "I" prefix to name the interfaces

    • @crazycode2578
      @crazycode2578 ปีที่แล้ว +40

      use "I" prefix to distinguish between interface and class

    • @Ctrl_Alt_Elite
      @Ctrl_Alt_Elite ปีที่แล้ว +37

      You should always give a reason lol, that's like saying "you should try to use inference over explicit typing... just cos".

    • @phill030
      @phill030 ปีที่แล้ว +5

      @@CodeOnBlocks watch the video "How to name things in Code" then you'll have an answer

    • @noesislogos
      @noesislogos ปีที่แล้ว +15

      @@Ctrl_Alt_Elite because it's a bad practice to clean code. It's more efficient to name things like "UserProps", describing the objective of that interface.

    • @brucewayne2480
      @brucewayne2480 ปีที่แล้ว +2

      I use Types over interfaces because of type utilities and with types you can create something like TUserId = string while you cannot do that with interfaces
      And I use T as prefix

  • @kajacx
    @kajacx ปีที่แล้ว +6

    The "satisfies" keyword looks really cool. I wonder if it can be used for an implicit cast.
    The "pass 100 into the enum function" is a thing from a horror. This is C# levels of bad. Does that still happen will all strict modes being turned on?

    • @kardashevr
      @kardashevr ปีที่แล้ว +3

      they fixed it in 5.0 beta

  • @asyourlipslounge
    @asyourlipslounge ปีที่แล้ว

    Lots of great content on this channel. Take my money.

  • @Fernando-du5uj
    @Fernando-du5uj ปีที่แล้ว

    I've been doing all these mistakes. Gonna fix them. Thanks alot.

  • @calvinchance5444
    @calvinchance5444 ปีที่แล้ว +1

    great video. would help if you talk slowly or maybe have some transition in between the tips or just maybe pause for two seconds in between. thanks for the video!

  • @alfabetatest
    @alfabetatest ปีที่แล้ว +2

    The first thing that comes to my mind is "Damn 'I'-prefixed Interfaces again…". A behavior you mostly see in the Microsoft-bubble (C# and MS-inspired C/C++). No one else does it and it's actually distracting when reviewing code since I won't care about the implementation-details here. It's should actually just be a User and Admin/AdminUser! It really doesn't matter it it's a interface, a type or a class but the I-prefix suggests that it's important, although it isn't.

  • @heartofcode5372
    @heartofcode5372 หลายเดือนก่อน

    @5:00 is that actually inference or type narrowing?

  • @velkanalpha
    @velkanalpha ปีที่แล้ว

    Excelent video totally understood 'satisfies', utility types and 'is', saved to watch untill I memorize.

  • @AmodeusR
    @AmodeusR ปีที่แล้ว +2

    A better alternative to enums is using a javascript object as const.

  • @novailoveyou
    @novailoveyou ปีที่แล้ว +3

    What you got there, you said you use for all of your type declarations
    type MyVar = {
    myKey: 'myVal',
    myKey2: 'myVal2'
    }
    const myVar: MyVar = {
    myKey: 'myVal',
    myKey2: 'myVal2'
    }
    Is making you do twice as much work when changes to myVar come. First in type then in object itself. You could nicely avoid it like this
    const myVar = {
    myKey: 'myVal',
    myKey2: 'myVal2'
    } as const
    type MyVar = typeof myVar
    It's the same thing except now you'd work as you normally would with JS objects but with read-only types
    Please don't bash junior developers with such video titles
    Happy holidays everyone!

    • @dealloc
      @dealloc ปีที่แล้ว +1

      Yes. Infererence over repetition and manual typing. The point of TypeScript is that you want to get the most out of types without explicitly writing them.

  • @jordixboy
    @jordixboy 4 หลายเดือนก่อน +1

    these doesn't necesarily have to be junior mistakes. If you are a generalist, I code in any language that's needed, this might be just due to not having all the language knowledge.

  • @isfland
    @isfland 9 หลายเดือนก่อน

    string | ICustomImage is not types' intersection, it's an union

  • @FSRezende
    @FSRezende ปีที่แล้ว

    Amasing! Thanks for sharing!

  • @daheck81
    @daheck81 ปีที่แล้ว +19

    These are pretty subjective tbh. There are a lot of use cases where any or enums are a better choice.

    • @Vishtar_Official
      @Vishtar_Official ปีที่แล้ว +4

      Where any is a better choise? I had to use it only in projects with fucked up typings (any everywhere) for solve tasks at estimated time.
      Enum - yeah, i agree.

    • @alastairtheduke
      @alastairtheduke ปีที่แล้ว +1

      @@Vishtar_Official With any, you're essentially opting out of TS. You're saying, I don't want to benefit from TS benefit for this variable. Usually it means you're not understanding a type error message. Better to learn what's going on and keep your code type safe.

    • @daheck81
      @daheck81 ปีที่แล้ว +3

      @@alastairtheduke That's not what I mean. There are use cases where you don't want to create a hardlink to a specific module by relying on its types for example. There are quite a few of these abstractional situations

    • @marcospenadev
      @marcospenadev ปีที่แล้ว

      Default numbered enums are a nightmare on default. For example, say You have an enums of Status {Accepted, Working, Finished}
      At that moment Accepted = 0
      But if You assign that value like currentStatus = Status.Accepted
      Then the currentStatus becomes 0, wich is a falsy value and can mess up your logic if you are not paying attention.
      Enums should be used by default with string values, and numbers only if you really need It. You can also start your enums with 1 as the first value to avoid the falsy value problem

    • @LoganS91
      @LoganS91 ปีที่แล้ว

      @@marcospenadevYep. And this exactly supports what enums are intended for in 90 percent of cases. Usually enums are used to uniquely identify a type of something. You don’t care it’s value. You just care about a readable unique identifier.
      Enums also show up differently than constants in most IDEs. There I big readability advantage to visually identify when an enum is being used.
      Also, enums are easier to work with in type manipulations.
      It’s rare to run into any issue when using enums. And the argument, “well it compiles to JavaScript blah blah blah anyway” is such a weak reason. That is like someone arguing that you may as well write code in assembly because your code is getting compiled down to it anyway.
      Today, we write code for humans. Computers don’t need our help reading it.

  • @vukkulvar9769
    @vukkulvar9769 ปีที่แล้ว

    Enum are good even with numerical values as long as you do 2 things :
    - Explicitly set the numerical value
    - Make them "const enum" regardless of the enum being numbers or strings.
    The satisfies operator is horrible. You should be able to write it as
    const goodUser: satisfies IUser = { ... }
    Or at least
    const goodUser = { ... }

  • @benbrown1535
    @benbrown1535 ปีที่แล้ว

    const {} as const is preferrred over using enum entirely

  • @giuseppelanna
    @giuseppelanna ปีที่แล้ว +1

    1:06 that’s why it’s called unknown

  • @audiodrocher
    @audiodrocher ปีที่แล้ว +2

    Thanks. So much to learn 😊

  • @Tempeck81
    @Tempeck81 7 หลายเดือนก่อน

    1. Understand the "unknown" type in TypeScript to avoid bypassing type checks and compromising code reliability.
    2. Avoid using "any" type as it disables TypeScript's type checking, leading to potential errors and decreased code quality.
    3. Utilize type guards effectively to determine the type of a variable dynamically, enhancing code readability and reliability.
    4. Refrain from relying solely on enums with implicit numbering, as it can lead to ambiguous code and decreased maintainability.
    5. Make use of built-in utility types like "Partial" and "Omit" to enhance code clarity and avoid unnecessary complexity in TypeScript development.

  • @Atif1702
    @Atif1702 ปีที่แล้ว +2

    The I prefix you use with interface is obsolete for quite a while now

  • @stevejackson2643
    @stevejackson2643 ปีที่แล้ว +3

    You need to slow down, if this tutorial is meant for juniors. You’re talking at 100 mph

  • @louielee3583
    @louielee3583 ปีที่แล้ว

    Great tips, thank you!

  • @davidabu3170
    @davidabu3170 6 หลายเดือนก่อน

    in type script the | operator is union. type Tuser = string | number

  • @jewbarrymore_
    @jewbarrymore_ ปีที่แล้ว +1

    7:31 it is rather asserting than casting

  • @avneet12284
    @avneet12284 ปีที่แล้ว +1

    This was really excellent.

  • @MDo-ww9wm
    @MDo-ww9wm ปีที่แล้ว +1

    I just don't get the hate for enums. It seems people just don't like that they're so dissimilar to enums in the languages they learned before. It's pretty neat that you can use them as a type.
    Compare:
    enum Color {
    WHITE = "white",
    BLACK = "black"
    }
    const color1: Color = Color.WHITE;
    with:
    const Color = {
    WHITE: "white",
    BLACK: "black"
    } as const;
    type Color = "white" | "black"; // Repetititve. An absolute pain to refactor with large objects.

    • @Budaeku
      @Budaeku 11 หลายเดือนก่อน

      It causes problems when importing them from another package with isolatedModules set in tsconfig. The problem is that only the type gets imported but the values don’t, or at least they’re not available statically, so a lot of inference doesn’t work

  • @guilhermebabugia8562
    @guilhermebabugia8562 ปีที่แล้ว

    is there any difference if I change to: function isAdminUser(object: unknown): object is IAdminUser { return Boolean(object?.token); } ?

  • @jackshephard7920
    @jackshephard7920 ปีที่แล้ว

    Very practical tips. Thanks!

  • @dalgeubam
    @dalgeubam ปีที่แล้ว

    @CoderOne what is the extension causing the function names to stick to the top when you scroll?

  • @daph7017
    @daph7017 ปีที่แล้ว +1

    What is the theme used in VSC?

  • @azizoid
    @azizoid ปีที่แล้ว

    11.20 why not to use
    Const BetterState = {
    Asd:”123”
    } as const

  • @noelfrancisco5778
    @noelfrancisco5778 ปีที่แล้ว

    Very helpful tips, I've learned a lot. Thanks :)

  • @igordasunddas3377
    @igordasunddas3377 ปีที่แล้ว

    Awesome video, thank you!

  • @yakimovev
    @yakimovev 5 หลายเดือนก่อน

    What color theme on a video?

  • @ELYUSEF
    @ELYUSEF ปีที่แล้ว

    thank you so much
    I liked the theme you're using, what is it called ?

  • @maxhweb
    @maxhweb ปีที่แล้ว

    superb explenation very clear thanks a lot !

  • @steiljeds
    @steiljeds ปีที่แล้ว

    Thank you so much!!

  • @yaakovisaacs
    @yaakovisaacs ปีที่แล้ว

    Wow, I'm impressed. You really know your stuff and explained this in such a great way. Thank you!

  • @somebody-17546
    @somebody-17546 ปีที่แล้ว

    thank you. now i know typescript can satisfy Operator

  • @Iam_AndersonP
    @Iam_AndersonP ปีที่แล้ว

    i loke alot all those tips, also the enum is a good one and the one i most use for strict declarations

  • @wisdomelue
    @wisdomelue ปีที่แล้ว

    thank you🎉

  • @iamikhan
    @iamikhan 2 หลายเดือนก่อน

    great tips, only thing, if you could slow done little bit would be great :)

  • @travelJS
    @travelJS ปีที่แล้ว

    Morning with this ❤

  • @codingprojects4002
    @codingprojects4002 ปีที่แล้ว

    Thank you for sharing those amazing tips. :)

  • @yaroslavpanych2067
    @yaroslavpanych2067 ปีที่แล้ว +1

    Simply mean turn of the Typescript "type-checks" "
    Someone is junior English ;)

  • @doniaelfouly4142
    @doniaelfouly4142 ปีที่แล้ว

    Thanks

  • @immer5680
    @immer5680 ปีที่แล้ว

    That was helpful, thanks

  • @janpaul74
    @janpaul74 ปีที่แล้ว +1

    "A huge mistake is not using the `satisfies` operator". Something that exists for about a month. *sigh*

  • @rajatfulmali9815
    @rajatfulmali9815 21 วันที่ผ่านมา

    First become a junior to learn the senior ☝

  • @doniaelfouly4142
    @doniaelfouly4142 หลายเดือนก่อน

    Thanks

  • @bojack4800
    @bojack4800 ปีที่แล้ว

    thank you, that awesome!

  • @ThomasJunkOS
    @ThomasJunkOS ปีที่แล้ว

    I find your OOD a bit strange. I know it is for the sake of examples but having a Pet class and having dogs and cats and accessing Pet.meow() after 1) a typecheck and b) a cast seems strange to me. The point of having a parent class is to have polymorphism at hand to abstract meowing or barking away. Under what circumstances does it make sense to have a uniform group of things when you a) know it is not uniform and b) do not need uniformity at all?

  • @Wolfram-d9j
    @Wolfram-d9j ปีที่แล้ว

    thank you

  • @Metruzanca
    @Metruzanca ปีที่แล้ว

    I always forget the is keyword is a thing. My main take away from this video is I need to use the return type : T is R more.

  • @backupmemories897
    @backupmemories897 ปีที่แล้ว

    if u tell p = cat why you have to check it if its a cat? are you doubting it? sorry im new at programming

  • @RafaelMilewski
    @RafaelMilewski ปีที่แล้ว +1

    One mistake you didnt avoid was prefixing interfaces with "i" as in IUser...

    • @alastairtheduke
      @alastairtheduke ปีที่แล้ว

      Why is that a mistake? No wait , don't answer that. You made a mistake when you mistook opinions for facts.

  • @GallowsofGhent
    @GallowsofGhent ปีที่แล้ว +3

    Hey juniors, if this is you watching, please don't be vocal about this new trend about enums and not using them. These kinds of opinions are only accepted by your peers if they consider you a senior, and won't necessarily win you many brownie points with interviewers. If they bring it up to you, just smile and listen and nod. But don't bring it up since this is honestly a pretty out there quirk and trend.
    If you establish the contract of the type and then break it by going around it, I'm not going to think the code or the language is bad. I'm going to add a review comment telling you not to do that. It sure is quirky that the compiler doesn't throw an error for such things, but I'm not in the business of tempting fate or acting smart, do I'm not about to lose sleep over this and you probably shouldn't either.

  • @seunghwanjeong5348
    @seunghwanjeong5348 ปีที่แล้ว +1

    Thank you for really useful tips !!
    By the way, I just wonder why you named IUser, IAdminUser types intead of just User, AdminUser?

    • @ngamsomset
      @ngamsomset ปีที่แล้ว +2

      it's a common way to name your type declaration. He used Interface so he named it starting with an I, if he use Type he might use T as the starting alphabet.

    • @seunghwanjeong5348
      @seunghwanjeong5348 ปีที่แล้ว +1

      @@ngamsomset I got it! Thank you so much😄😄😄

    • @TheJohnreeves
      @TheJohnreeves ปีที่แล้ว +5

      Bad habits in my opinion. Prefixing types with "i" for interface is an antipattern in Typescript, it doesn't tell you anything useful. Types and interfaces should be interchangeable and if you have an interface and a class, they should just be give names that naturally make sense.

  • @presDev
    @presDev ปีที่แล้ว

    real good one!

  • @Grillparzer
    @Grillparzer ปีที่แล้ว +1

    Intellisense is not pronounced as Intel-license.

  • @chrzan9608
    @chrzan9608 ปีที่แล้ว

    What you refer to as an intersection is in fact a union, so that's a pretty big mistake on someone who is lecturing about mistakes that juniors make...You might want to revise that since a union and an intersection are completely different concepts.

  • @thatWebGuySolutions
    @thatWebGuySolutions ปีที่แล้ว

    Good stuff!

  • @mateuszkulesza8528
    @mateuszkulesza8528 ปีที่แล้ว

    nice content!

  • @jiitukadu372
    @jiitukadu372 ปีที่แล้ว

    "Property has no initializer and is not definitely assigned in the constructor"
    i got these error many times, how to resolve these errror?

    • @MDo-ww9wm
      @MDo-ww9wm ปีที่แล้ว +1

      tsconfig.json -> compilerOptions: strictPropertyInitialization: false

    • @jiitukadu372
      @jiitukadu372 ปีที่แล้ว

      thanks, but "strictPropertyInitialization: false" is needed for type-safe ,
      is their any other way...

    • @MDo-ww9wm
      @MDo-ww9wm ปีที่แล้ว +1

      @@jiitukadu372 All it does is (dis)allow you to declare class properties without giving them a value directly or in the constructor. It has nothing to do with type safety.

  • @YourModdedControllers
    @YourModdedControllers ปีที่แล้ว

    At the end of the day, the panel who hires you determines if you're junior or senior.

  • @johnddonnet5151
    @johnddonnet5151 ปีที่แล้ว

    The Omit one is great, also yeah, who could be stupid enough to think using numbered enums is good, either you name them with string or don't use them.
    \