Open In App

TypeScript Less Common Primitives Type

Last Updated : 03 Nov, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads