Stop Using {} In TypeScript

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ส.ค. 2023
  • 🌎 Find Me Here:
    My Blog: blog.webdevsimplified.com
    My Courses: courses.webdevsimplified.com
    Patreon: / webdevsimplified
    Twitter: / devsimplified
    Discord: / discord
    GitHub: github.com/WebDevSimplified
    CodePen: codepen.io/WebDevSimplified
    #Shorts

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

  • @1DrowsyBoi
    @1DrowsyBoi 2 หลายเดือนก่อน +247

    Type-safe language programmers:
    "Look what they need just to mimic a fraction of our power."

    • @abh1yan
      @abh1yan 29 วันที่ผ่านมา +2

      hate from javascript developer

    • @bbarreir0153
      @bbarreir0153 21 วันที่ผ่านมา +1

      In all fairness, strict TS is almost like Java, as long as you dont use "any" or some stupid typing. We can just ignore the typing and if you don't do weird things you'll almost always get the correct type inferred, specially with the latest versions of TS. TS is not JS

    • @mr.k8660
      @mr.k8660 9 วันที่ผ่านมา

      You ain't building no web UI with those type safe languages tho

  • @abhayprince
    @abhayprince 11 หลายเดือนก่อน +330

    I name it key instead of index.
    { [key:string] : unknown }

    • @j.r.r.tolkien8724
      @j.r.r.tolkien8724 11 หลายเดือนก่อน +26

      Makes more sense. I thought it had to be named index.

    • @dorian0623
      @dorian0623 7 หลายเดือนก่อน +5

      I'd also use key or property but index should be just fine as it stands for index signature

    • @ninhdang1106
      @ninhdang1106 7 หลายเดือนก่อน +2

      Same thing but I use the Record syntax instead. Kinda more pleasing to look at

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

      And it works

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

      Same here 👌

  • @christianpuldon7201
    @christianpuldon7201 9 หลายเดือนก่อน +29

    For a split second I read "Stop using TypeScript"

    • @FkDJT-ut1hm
      @FkDJT-ut1hm 19 วันที่ผ่านมา +2

      And that would have been good advice.

    • @teawrld5976
      @teawrld5976 7 วันที่ผ่านมา +1

      ​@@FkDJT-ut1hm why?

    • @anere5326
      @anere5326 3 วันที่ผ่านมา

      @@teawrld5976 he has been paralysed by fear

  • @und0
    @und0 8 หลายเดือนก่อน +13

    you should mention the `object` (note lowercase) this is the most generic pure object you can specify, usually useful it you're extended a generic. function foo (bar: T) { return Object.keys(bar) }

  • @devperatetechno8151
    @devperatetechno8151 11 หลายเดือนก่อน +78

    thanks kyle, keep with the snippets of TS

  • @nomadshiba
    @nomadshiba 10 หลายเดือนก่อน +2

    also you can do `Record`
    `PropertyKey` shorthand for `string | symbol | number`

  • @thefanboy3285
    @thefanboy3285 3 หลายเดือนก่อน +4

    The title made me think for a moment there was a trick in TS to get rid of the block scope delimiters "{" "}" lol

  • @RonnieMcNutt_Mindblowing
    @RonnieMcNutt_Mindblowing 11 หลายเดือนก่อน +74

    Me watching this even though I know nothing about coding: Very nice

    • @IAmLesleh
      @IAmLesleh 11 หลายเดือนก่อน +18

      No better time to start

    • @x3zlo
      @x3zlo 11 หลายเดือนก่อน +2

      ​@@IAmLeslehI think this person wants to finish, not start 😏

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

      Fuck typescript

    • @ivansostarec2564
      @ivansostarec2564 5 หลายเดือนก่อน +1

      You should try coding

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

      ​@@IAmLeslehactually it's the worst time to start

  • @charliesta.abc123
    @charliesta.abc123 11 หลายเดือนก่อน +2

    Thank you so much Kyle! I've been struggling to type the ioredis georadius result. This will help me

  • @ffuego9751
    @ffuego9751 11 หลายเดือนก่อน +10

    These shorts are awesome, goat js/ts content creator

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

    Record won't exclude arrays though.
    If you want to exclude arrays, you'll need to do `Record`.
    There are a few small corner cases where `Record` is too strict, but those don't come up much in user-land.

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

      You sure?
      type personData = Record;
      // This will cause a TypeScript error because it doesn't match the declared type
      function f(obj: personData) {
      return obj;
      }
      f(["3"])
      // Argument of type 'string[]' is not assignable to parameter of type 'personData'.Index signature for type 'string' is missing in type 'string[]'.ts(2345)

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

      I assumed you’d be putting the type in a generic (which is usually what you want - if your use case looks like that, it’s probably fine to just use `object` and allow arrays)

    • @theefeold
      @theefeold 24 วันที่ผ่านมา

      how tf are you supposed to make an array with string indexes?

    • @andrewjarrett132
      @andrewjarrett132 22 วันที่ผ่านมา

      ​@@theefeoldit's not that arrays have string indexes, it's that arrays have methods, and methods are strings. The symbol trick is a hack that only works because it takes advantage of how index signatures work in the TS type system -- and it's not bulletproof. An interface declared that way -- interface MyInterface { [x: symbol]: unknown } will behave* differently (unfortunately)

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

    Super helpful! Relaxes my brain to think of it this way

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

    Deno helped me a lot to learn TypeScript and avoid some bad practices such as this one

  • @dimarak8866
    @dimarak8866 2 หลายเดือนก่อน +6

    One could just type it like this:
    type Obj = {
    name: string;
    surname: string;
    };
    Record is only needed if you want to build a versatile function that handles different objects with the same structure or if you expect an object from an API f.ex. to change property names in the future

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

      You can't pass any object with the type you defined. Thats the whole point of this short.

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

      @@IStMl Isn't date an object..
      The point of this short is specifically to allow objects where the key is of type string and the value is unknown to ts (or similar definitions)
      but ANY object should accept date

  • @sterin557
    @sterin557 11 หลายเดือนก่อน +21

    Need more typescript stuff

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

    Commenting so that youtube recommends more of these type of shorts❤

  • @roshan4348
    @roshan4348 20 วันที่ผ่านมา

    Great typescript video!

  • @risitas5874
    @risitas5874 11 หลายเดือนก่อน +1

    Thanks for teaching me this, although I don't think I will be adopting this pattern. The codebase has to be already be using it

  • @j.r.r.tolkien8724
    @j.r.r.tolkien8724 11 หลายเดือนก่อน +40

    More please. I'm transitioning to Typescript.

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

      don’t

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

      They were not seen again... That's the price of moving to TS.

    • @j.r.r.tolkien8724
      @j.r.r.tolkien8724 หลายเดือนก่อน +1

      There's literally no price of moving to TS. That's the great thing about it. Just wirte your js in a .ts file. You'll lose nothing and whatever you can add a type to you reap the benefit. You don't have to go deep into types. You can just minimize the mistakes.

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

      @@j.r.r.tolkien8724 the price is now you use typescript and you have officially adopted the worst implementation of types in any programming language

    • @Pr0methium
      @Pr0methium 23 วันที่ผ่านมา

      @@j.r.r.tolkien8724 Yeah + intellisense, your code is eventually more safe logic-wise as well, pretty good for a production environment.

  • @nozomi_tailwind
    @nozomi_tailwind 11 หลายเดือนก่อน +3

    i use the 2nd method cz i can easily understand like writing the object itself

  • @ibnlanre
    @ibnlanre วันที่ผ่านมา

    type Param = Record;
    Object keys can be a string | number | symbol.

  • @bob_kazamakis
    @bob_kazamakis 11 หลายเดือนก่อน +3

    {} is actually pretty powerful when you want to accept any value that isn’t undefined or null. It’s an any, but that any must exist

    • @GurjotSingh-no4hx
      @GurjotSingh-no4hx 11 หลายเดือนก่อน

      wouldn't the same apply to the 2 alternate solutions he provided?

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

      You can make your intention more clear by using NonNullable

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

      If you do not want to accept null or undefined then you can configure you typescript's strictNullChecks to true

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

      @@GurjotSingh-no4hxno. Record limits the expectation to an object and not any of the aforementioned primitives

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

      @@alexcoroza4518that’s not the point or intent of what I’m saying

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

    I've been all up in Record in the past months. It seems cleaner to my eyes for some reason than the key index approach (2nd version he showed).

  • @PatoFrango
    @PatoFrango 28 วันที่ผ่านมา

    I think something like this in Python wouldn't be a problem since the language clearly distinguishes between "dictionaries" and objects that are "instances of classes"

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

    Also you can still use it, its a great way to tell that something is anything but non nullable

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

    I knew about Record but then I wanted to type an empty object (to fill with keys and value later) and that turned out to be a problem. Using {} works for the moment.

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

    this makes TS A LOT more complex than I thought...

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

    I love the record syntax over the 2nd one

  • @solomonowusu-ansah1751
    @solomonowusu-ansah1751 7 หลายเดือนก่อน

    I use the second option. But I've learnt another way. Thanks

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

    Hey thanks , never knew about this

  • @cafelutsa_
    @cafelutsa_ 11 หลายเดือนก่อน +98

    Please stop producing videos with the format of "Stop doing X thing"

    • @TheSaintsVEVO
      @TheSaintsVEVO 11 หลายเดือนก่อน +5

      Elaborate

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

      @@TheSaintsVEVO Elaborate on what?

    • @samipplays
      @samipplays 11 หลายเดือนก่อน +1

      Everybody seems to like it tho

    • @pepperdayjackpac4521
      @pepperdayjackpac4521 11 หลายเดือนก่อน +1

      Why?

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

      ​@@pepperdayjackpac4521as it gets more views/ more people are curious

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

    Doing “Record” also works

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

      did you not watch the short?

  • @OliverEbsworth
    @OliverEbsworth 11 หลายเดือนก่อน +5

    I use an Interface and mark each things as its type
    instance objI {
    name: string,
    email: string,
    image: string,
    }
    Is this wrong?

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

      yeah. in Angular this is how they type things and it should be on most projects using typescript

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

      @@alexcoroza4518 cheers man, I appreciate your reply.

    • @asherrfacee
      @asherrfacee 11 หลายเดือนก่อน +1

      Using an interface/type/class when you are expecting a specific object type is definitely the best option.
      In the rare case that you want to accept any object except a Date, instead of using his solution, I recommend using a conditional type:
      function processObjectWithoutDate(obj: T extends Date ? never : T): void {
      // Process the object
      // ...
      }

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

    I'm guilty of doing this. Massive thanks 👍🏾

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

    Actually useful, I could use a longer video, interesting topic.

  • @justindouglas3659
    @justindouglas3659 11 หลายเดือนก่อน +24

    Can you do a typescript tutorial?

    • @FurryDanOriginal
      @FurryDanOriginal 11 หลายเดือนก่อน +3

      I can recommend Matt Pocock for that.

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

      @@FurryDanOriginal ok thnx do ypu happen to know someone for php. Seems i need to learn it anyway.

    • @FurryDanOriginal
      @FurryDanOriginal 11 หลายเดือนก่อน +2

      @@justindouglas3659 Unfortunately no. Outside of some basics, I never needed PHP nor was interested in it. But by searching for PHP tutorials you surely should find a lot of creators and just stick to the one who seems to flow with your prefered style of learning the best.

    • @Me-vc4sf
      @Me-vc4sf 3 หลายเดือนก่อน

      ​@@justindouglas3659 "php for beginners " from laracast channel one of the best php tutorial ever

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

    amazing, thanks!

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

    Great shorts normally but I never bump into this issue, which is confusing as you say "by far the most common issue". If it's being passed like that its normally more defined like as an interface, or as you recommend a type. I never go near the Object type directly.

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

      Yea what's the point of using typescript if you don't want to define what the structure looks like lol

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

    Record

  • @hadawardgz
    @hadawardgz 10 วันที่ผ่านมา

    Sure, now try this and see if you can pass a date object:
    type Foo = {
    bar: string;
    }
    It will only pass if date has the properties that the object needs. If it doesn't, then it doesn't work, and if it does, great, I won't look for properties other than those necessary. And, for any reason if you need to allow objects of unknown properties then you can just:
    type Param = {
    [K: PropertyKey]: unknown
    };

  • @FkDJT-ut1hm
    @FkDJT-ut1hm 19 วันที่ผ่านมา

    Cool. I'll go back to writing code that doesn't break because of a lack of knowledge when it comes to data types and how they are used; ergo needing a whole other language just to over-specify my dataums.

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

    object, Record, …And object of ANY form: Record

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

    {} means "anything but a `null` or `undefined`"!

  • @pierrehenriot2480
    @pierrehenriot2480 11 หลายเดือนก่อน +2

    Are you Captain Pike's son ?

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

    Cool, thanks 👌🏾

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

    bro how u so majestic

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

    By far the most common mistake junior devs make is thinking they are smarter than a compiler and throw away readability for pointless char saving ideas. Also doing micro-optimizations on the behalf of readability...
    Edit: Just waiting for the smartass to write: "less chars = less file weight and possibly less exec time"... the compiler is there for a reason.

  • @Mohamed_MDJ
    @Mohamed_MDJ 3 หลายเดือนก่อน +1

    I didn't learn typescript yet , but I can easily understand what did you write, so is it very simple?

  • @bronzekoala9141
    @bronzekoala9141 11 หลายเดือนก่อน +13

    Nice tip, but how on earth is this the "most common mistake"?? I've never even come into a situation where I could've done this mistake.

    • @sqfzerzefsdf
      @sqfzerzefsdf 11 หลายเดือนก่อน +1

      @bronzekoala9141 like he said everything inherits from object so there's a lot of potential reason to pass one around and there's plenty of room for mistakes due to how unintuitive something as abstract as object is

    • @asherrfacee
      @asherrfacee 11 หลายเดือนก่อน +1

      I agree, not a common mistake. I’ve been writing typescript for 10 years. This is a weird niche case where you want strictly compile time type checking for any object except a Date. I say strictly compile time cause you could always use runtime validation for Date very easily which most cases would likely use.
      His advice to never use object I find to be questionable advice, and his suggested use of the Record utility type is wrong according to the Typescript team. Record should only be used when you want strictly typed dictionary-like object.
      If you want to exclude date just use a conditional type:
      function processObjectWithoutDate(obj: T extends Date ? never : T): void {
      // Process the object
      // ...
      }

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

      maybe it's really uncommon, but still the most common lol

  • @patrickconrad2874
    @patrickconrad2874 22 วันที่ผ่านมา

    Trying to make a react query clone and having a hard time wrapping my head around this concept. I want to easily store state values on any given page. This works to pass unknown state types, but now I'm wondering if there is a way to get full typing from the unknown values down stream? Anyone have any advice on this concept?

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

    What's the name for this? How the folder to put those kind of object factory could be named?

  • @mahadevovnl
    @mahadevovnl 11 หลายเดือนก่อน +1

    What about nested objects

  • @blueghost512
    @blueghost512 11 หลายเดือนก่อน +1

    Which is due to missing tsconfig rules

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

    Let's always do alot of good

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

    everyday I think I get it and then I get proven wrong

  • @SRG-Learn-Code
    @SRG-Learn-Code 11 หลายเดือนก่อน +14

    I hope JStypes come soon so we can stop with the TS madness.

    • @richardflosi
      @richardflosi 11 หลายเดือนก่อน +2

      There is a spec for js comment annotations is the works, but it’s still some that 3rd parties like TS would read for typing.

  • @RS-fz4ps
    @RS-fz4ps หลายเดือนก่อน

    If you knew the desired members of you Param, why wouldn’t you define a class for it instead? Isn’t that the point of typescript?

  • @trFirzen
    @trFirzen 11 หลายเดือนก่อน +2

    I see these videos after I do these mistakes lol. Are you following my code?

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

    You could do that...but...should you?
    you can `typeof ` an object or create a class.
    At this point you might as well just say `any`

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

    This won't work if you have an object that is declared as an interface.

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

      just dont mix types and interfaces

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

    I haven't seen anyone typing object Object yet

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

    Thankss

  • @HellMuerto
    @HellMuerto 7 วันที่ผ่านมา

    Same people that makes fun of Java because « bOiLerPlaTe »

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

    My frustration is anytime I use typescript with a 3rd party library with broken, missing, and overly complicated types. Fighting both Typescript and a new library, is too much. I usually give up and revert to "any."

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

    Why not specifying the fields for the object type?

  • @gronkhfp
    @gronkhfp 3 หลายเดือนก่อน +1

    Or just create an Interface for your models

  • @mystica-subs
    @mystica-subs หลายเดือนก่อน

    What do you mean the object works and the date no longer works? I don't see a difference? Where is the actual output of this code?

  • @olhoTron
    @olhoTron 25 วันที่ผ่านมา

    Just stop using typescript and use an actually typed language

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

    This one doesnt work with interface. I have googled for some solutions, but almost of it are recommended replace type instead or using Record which i see no different from Object/any. Does anyone have another idea!?

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

      You should only use Record utility type when you want a strictly defined dictionary-like object, so his solution is more of a hack.
      In his example, it’s a simple case where you want to just exclude the Date type, so using a simple conditional type to exclude Date is the best option:
      function processObjectWithoutDate(obj: T extends Date ? never : T): void {
      // Process the object
      // ...
      }

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

    Thanks!

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

      You look like a Meghan Markle copycat

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

      You are very welcome!

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

    What about nested objects?

  • @chris-zlrr
    @chris-zlrr หลายเดือนก่อน

    thats cool

  • @mosesgelberg
    @mosesgelberg 10 วันที่ผ่านมา

    Why `unknown` and not `any`? What's the difference?

  • @pixelotetm
    @pixelotetm 11 หลายเดือนก่อน +1

    That record is the same as Map< String, dynamic> in dart programing, actually for dart to be able to work with Json, it needs to be converted to a Map of Strings keys and dynamic values

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

      If you want a custom type for representing JSON objects in typescript, that provides additional type safety then I recommend the following:
      type JSONValue = string | number | boolean | null | JSONValue[] | Record;

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

    I hate typescript so EXTRA

  • @markdesign1354
    @markdesign1354 11 หลายเดือนก่อน +1

    wow, typescript is so complicated and non-intuitive.

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

    But isn't index like a main page?

  • @Lucas-mu5no
    @Lucas-mu5no 7 หลายเดือนก่อน

    Awesome

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

    I use lowercase 'object' cuz it's simpler

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

    I think biggest mistakes is not properly setting up a tsconfig.

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

    but {} gives me error every time !!

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

    An object should be an object! What?

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

    why not interface?

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

    Actually the most common would be doing front end dev 😂

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

      Agree 😢😢 especially CSS

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

    Why unknown instead of Any

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

    why not use interface?

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

    What's the difference between using Record & Record ?

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

      Unknown will throw an error until you check the type. Any will disable type checking and you don't have to check the type before using whatever you want

  • @metamike_23
    @metamike_23 27 วันที่ผ่านมา

    java developers looking at this

  • @roronoa_d_law1075
    @roronoa_d_law1075 11 หลายเดือนก่อน +1

    Is it possible to have not string keys ?

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

      Yes, you can also use numbers and symbols:
      // Using numbers as keys
      type NumberRecord = Record;
      const numberObject: NumberRecord = {
      1: "One",
      2: "Two",
      3: "Three"
      };
      // Using symbols as keys
      const symbolKey1 = Symbol();
      const symbolKey2 = Symbol();
      type SymbolRecord = Record;
      const symbolObject: SymbolRecord = {
      [symbolKey1]: 42,
      [symbolKey2]: 99
      };

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

    Damn I make this mistake 😂

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

    Cuz in reality you don't want an object you want smth like a dictionary.

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

    Hello Kyle you have been of a great help to me in the last few years as a self-taught developer. Right now I need a job. It has been a real issue for me. I have been a developer of self, building projects for clients as a freelance but I really want to go out of this shell and work in real life company. This is a great problem for me. Please I need your help.

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

    What if {name: string} ?

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

    or just use interfaces?

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

    Why not use an interface ?

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

    An object... That wasn't too hard

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

    hey kyle, whats the difference between unknown vs any?

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

      They are like the exact opposites. Any allows any operation because it could be anything, unknown allows none without narrowing down the type. It’s better to read the documentation and code examples to really get the gist of it

  • @Darkpill-2
    @Darkpill-2 9 หลายเดือนก่อน

    JavaScript has bigger problems than type checking. This is why projects are starting to dump typescript.

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

    I type script but it's a necessary evil I suppose

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

    Typescript generating more bytecode this slows down performance