Discover this podcast and so much more

Podcasts are free to enjoy without a subscription. We also offer ebooks, audiobooks, and so much more for just $11.99/month.

Hasty Treat - Enums in JS (GraphQL and Typescript)

Hasty Treat - Enums in JS (GraphQL and Typescript)

FromSyntax - Tasty Web Development Treats


Hasty Treat - Enums in JS (GraphQL and Typescript)

FromSyntax - Tasty Web Development Treats

ratings:
Length:
13 minutes
Released:
Oct 5, 2020
Format:
Podcast episode

Description

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
Released:
Oct 5, 2020
Format:
Podcast episode

Titles in the series (100)

Full Stack Developers Wes Bos and Scott Tolinski dive deep into web development topics, explaining how they work and talking about their own experiences. They cover from JavaScript frameworks like React, to the latest advancements in CSS to simplifying web tooling.