symbol
A primitive value created by Symbol() that is guaranteed unique, used as a property key that can never clash with another.
In more detail
Two symbols with the same description are still different, so libraries use them for hidden or internal keys. Decorator metadata is stored under the built-in Symbol.metadata key. Inside the compiler, symbol also names the record the binder keeps for each declaration, which is a different thing.
Example
const internalKey: symbol = Symbol("session_id");Related terms
- primitive type — A basic built-in type, such as a whole number or true-or-false, whose values are held directly rather than as objects.
- decorator metadata — An object shared by all decorators on a class, reached through context.metadata and later readable at Symbol.metadata on the class.
Taught in
- The Compiler Pipeline: tsc, AST And Code Emission — Production TypeScript
- Verify Your Environment: Running tsc And Bun TypeScript — Production TypeScript
- Primitive Types: String, Number, Boolean, Bigint And Symbol — Production TypeScript
- never: The Bottom Type And Exhaustive Switch Checking — Production TypeScript
- Generic Constraints: extends, keyof And Indexed Access — Production TypeScript
- ECMAScript Modules, CJS Interop And verbatimModuleSyntax — Production TypeScript
- Modern Decorators: Stage 3 Standards And Class Metadata — Production TypeScript