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:
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.
TypeScript Less Common Primitives Type
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
- Symbol
Contact Us