7

Hasty Treat - Enums in JS (GraphQL and Typescript)

 3 years ago
source link: https://syntax.fm/show/289/hasty-treat-enums-in-js-graphql-and-typescript
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Oct 5th, 2020

Hasty Treat - Enums in JS (GraphQL and Typescript)

👇 Download Show✏️ Edit Show Notes

In this Hasty Treat, Scott and Wes talk about enums in JS — what they are, what they do, and how they work in JavaScript.

LogRocket - Sponsor

LogRocket lets you replay what users do on your site, helping you reproduce bugs and fix issues faster. It's an exception tracker, a session re-player and a performance monitor. Get 14 days free at logrocket.com/syntax.

Show Notes

03:11 - What are enums?

  • A type restricting variables to one value from a predefined set of constants
  • Direction = UP / DOWN / LEFT / RIGHT
  • Role = ADMIN EDITOR AUTHOR VIEWER
  • Day of the Week

05:12 - In GraphQL

  • enum Role { ADMIN EDITOR AUTHOR VIEWER}

07:05 - In TypeScript

  • First, declare the type:
    • enum direction = { UP, DOWN, LEFT, RIGHT }
  • Then when you defined your function, use that type
    • type User { role: Role } or type User { role: [Role] }

08:49 - In JavaScript

Links

Tweet us your tasty treats!


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK