

Hasty Treat - Enums in JS (GraphQL and Typescript)
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.

Oct 5th, 2020
Hasty Treat - Enums in JS (GraphQL and Typescript)
👇 Download Show✏️ Edit Show NotesIn 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
-
12
✏️ Edit Show NotesIn this Hasty Treat, Scott and Wes talk about JavaScript's drag and drop API — how it works, concerns, best practices, and more!...
-
12
Sep 24th, 2018Hasty Treat - Positivity and Web Development👇 Download Show✏️ Edit S...
-
5
Sep 17th, 2018Hasty Treat - Feedback and Criticism👇 Download Show✏️ Edit Show Notes
-
16
Dec 31st, 2018Hasty Treat - CSS and JS Pointer Events👇 Download Show✏️ Edi...
-
9
Aug 27th, 2018Hasty Treat - Framer X and Prototyping Tools👇 Download Show✏️ Edit Show...
-
6
Aug 9th, 2021Hasty Treat - TypeScript Utility Types👇 Download Show✏️ Edit Sho...
-
6
Aug 16th, 2021Hasty Treat - The Weird and Wonderful <link> Tag👇 Download Show
-
6
Jan 18th, 2021Hasty Treat - CSS Typography and Systems👇 Download Show✏️ Edit Show Notes
-
6
✏️ Edit Show NotesIn this Hasty Treat, Scott and Wes talk about the differences between compilers and build tools in TypeScript. Sanity - Spo...
-
4
Mar 22nd, 2021Hasty Treat - Effortless Custom GraphQL with GraphQL Codegen👇 Download Show
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK