Open In App
Related Articles

TypeScript Less Common Primitives Type

Improve Article
Improve
Save Article
Save
Like Article
Like

TypeScript Less Common Primitives Type offers a rich set of primitive types to represent data. While most developers are familiar with types like number, string, boolean, and symbol, TypeScript also provides less common primitive types that can be incredibly useful in specific scenarios.

These are some Less Common Primitives Types:

Table of Content

bigint

This type represents arbitrary-precision integers. It can hold integers with an arbitrary number of digits, making it useful for working with very large numbers with precision.
Example:

Javascript




// Define a bigint variable
const myBigint: bigint = 1234567890123456789012345678901234567890;
  
console.log(myBigint);


Output:

bigint

output

Symbol

TypeScript provides a symbol type, which is used for unique identifiers. Symbols are primarily used as object property keys to avoid naming conflicts.

Example:

Javascript




// Define a symbol
const mySymbol: symbol = Symbol('mySymbol');
  
// Use the symbol as an object property key
const obj = {
    [mySymbol]: 'Hello!,Symbol !'
};
console.log(obj[mySymbol]);


Output:

2023-10-03T15_05_12

Symbol Output

Conclusion: In this article we have seen less common primitive types like bigint, undefined, null, void, never, and unknown provide powerful tools to handle various scenarios with precision. Understanding when and how to use these types can lead to more robust and type-safe code in your TypeScript projects. Explore these types further to leverage the full potential of TypeScript’s static typing.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 03 Nov, 2023
Like Article
Save Article
Similar Reads