RecipesChapter 2: Basic Types

Working with Symbols

Recipe 2.7 from The TypeScript Cookbook

const PROD: unique symbol = Symbol('Production mode')
const DEV: unique symbol = Symbol('Development mode')

function showWarning(msg: string, mode: typeof DEV | typeof PROD) {
 // ...
}
Open in TypeScript Playground →