meta_pixel
Tapesearch Logo
Log in
Syntax - Tasty Web Development Treats

Hasty Treat - Enums in JS (GraphQL and Typescript)

Syntax - Tasty Web Development Treats

Wes Bos

Tech News, News, Technology

4.9 • 1.2K Ratings

🗓️ 5 October 2020

⏱️ 13 minutes

🧾️ Download transcript

Summary

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} Then 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 Not in JS yet There is a proposal in stage 1 https://github.com/rbuckton/proposal-enum And a babel plugin: https://www.npmjs.com/package/babel-plugin-const-enum Can use case/switch Can use Object or Map keys Links Syntax 287: Hasty Treat - Records and Tuples in JavaScript Tweet us your tasty treats! Scott’s Instagram LevelUpTutorials Instagram Wes’ Instagram Wes’ Twitter Wes’ Facebook Scott’s Twitter Make sure to include @SyntaxFM in your tweets

Transcript

Click on a timestamp to play from that location

0:00.0

Monday, Monday, Monday,

0:02.0

Open wide Dev fans.

0:04.0

Get ready to stuff your face

0:06.0

with JavaScript, CSS, node modules, barbecue tips,

0:09.0

get workflows,

0:10.0

break dancing, soft skills, web development,

0:12.0

the hastiest, the craziest, the craziest development the hastiest the craziest the tastiest web development treats coming in hot here is

0:18.1

Wes Barracuda bars and Scott El Toroloco, Tolinsky.

0:25.0

Oh, welcome to syntax in this Monday.

0:29.0

Hastie treat.

0:30.0

We're going to be talking about genomes in JavaScript. This might be a word that you've seen before and don't know,

0:36.1

or maybe it's a word that you don't know and have no idea, or maybe you are up on enums.

0:41.0

But we're going to be talking all about enums, what they are, how you can use

0:45.2

them, and a little bit about what their situation is in JavaScript.

0:48.8

Now I personally use them in TypeScript.

0:50.7

So my name is Scott Tolinsky.

0:52.4

I'm a developer from Denver, Colorado and with me. Type

0:52.6

I'm a developer from Denver, Colorado and with me as always is the

0:56.3

one and only West Boss.

0:58.0

Hey everybody.

0:59.2

Hey, Wes.

1:00.9

This episode is sponsored by Log Rocket.

...

Please login to see the full transcript.

Disclaimer: The podcast and artwork embedded on this page are from Wes Bos, and are the property of its owner and not affiliated with or endorsed by Tapesearch.

Generated transcripts are the property of Wes Bos and are distributed freely under the Fair Use doctrine. Transcripts generated by Tapesearch are not guaranteed to be accurate.

Copyright © Tapesearch 2026.