Typescript - Tips & Tricks - Literal Types

Full Stack Developer and JavaScript and TypeScript enthusiastic.
Search for a command to run...

Full Stack Developer and JavaScript and TypeScript enthusiastic.
No comments yet. Be the first to comment.
In this series, You'll see some tips and tricks using Typescript
Welcome back! Today I'll talk about the keyof operator. This operator helps us to extract the object's properties such as Literal-types type Person = { firstName: string; surName: string; age: number; location: string; }; type PersonKeys = k...
Today, I wanna show you how to set up your devices with Antigravity using only the agentic mode, without touching any code. At the last CodeMotion Rome, I got my special badge. A CM Node, a special ha

As a developer, you have to take control of your projects every day. Whether it is a company repository, an open source project you maintain or collaborate on, or a simple pet project. Gaining control over your projects often depends on the platform ...

My Antigravity first experience

Write clear and insightful commit messages using AI and GitLens.

We are in the AI era. New models emerge daily, and many applications have already integrated AI into their workflows. Gemini, OpenAI, Copilot, Deepseek, Llama, and many others enable AI in your applications or help you write code, but they all need a...

Welcome back! Today I show you the Literal Types.
This feature permits you to create a set of relationship values.
type Direction = "North" | "South" | "East" | "West";
Literal types in this case create also a Type Guard of your field, so the compiler can detect your errors or your typos.
let directionError: Direction = "east" // Type '"east"' is not assignable to type 'Direction'
let direction: Direction = "East" // OK
You can create Literal Types from different types such as booleans, numbers, and strings, and you can combine together different types too.
type Valid = false | 0 | true | 1;
That's all for today See you soon guys!