Keys with Constants and Symbols
In this lesson, we will study how to use keys with constants and symbols.
We'll cover the following...
We'll cover the following...
Constant
Version 2.7 brings the possibility of accessing a property using a constant and symbol. This is a minor improvement because, before 2.7, it was possible to access (read and write) a constant or symbol, but not to define a field in an interface or type.
TypeScript 3.3.4
const Foo = "Foo"; // Constant valueconst Bar = "Bar"; // Constant valueconst Zaz = "Zaz"; // Constant valueconst objectWithConstantProperties = { [Foo]: 100, [Bar]: "hello", [Zaz]: () => {} };let a12: number = objectWithConstantProperties[Foo];let b2334: string = objectWithConstantProperties[Bar];console.log(a12);console.log(b2334);
The example defined three ...