4 TypeScript tips: as const, typeof, keyof and template string types

Поділитися
Вставка
  • Опубліковано 27 вер 2024
  • Just a few tips in context of when you would use them: as const, typeof, keyof and template string types

КОМЕНТАРІ • 10

  • @joostschuur
    @joostschuur Рік тому +4

    0:30 I don't understand what you mean with 'give me the keys that are typeof number' here. The type is a union of strings. Sure, treated as an array, they each have an index, but how is number relevant for the CourseCode type?
    That part went a little too fast for me :)

    • @vitorgouveia5378
      @vitorgouveia5378 Рік тому +3

      i'll tell you what i understood
      so, courses is an array, you can access it via number indexes, ok.
      "courses[number]" is telling the typescript compile the following:
      Look, I know "courses" is an array of these specific values (because its readonly), so, get me the values I'd get if i were to access it using a number
      and then it returns all the values in a union, because if you were to put a number in "courses[number]", like 0, "courses[0]", it would give you that value so, "courses[number" would be all the values in a union because the number is not defined
      im sorry, i explain things very badly

  • @gregr.v.5357
    @gregr.v.5357 Рік тому +1

    Great tips! Is the full TS course out yet?

  • @michaelm8044
    @michaelm8044 Рік тому

    Awesome, thank you

  • @PuneetShivram
    @PuneetShivram Рік тому

    @WesBos When is your new course on Typescript is going to roll out?

  • @pavolhejny
    @pavolhejny Рік тому

    What (like-handwritten) font do you use for names?

    • @WesBos
      @WesBos  Рік тому +1

      Operator mono!

  • @prateeksingh8240
    @prateeksingh8240 Рік тому

    Can you tell us what is your theme name??