Home > Blockchain >  Is it possible to get the value of a type as a constant
Is it possible to get the value of a type as a constant

Time:09-09

Is it possible to do something like:

type TrueType = true;
const someVar = GetTypeValue<TrueType>(); // This is where the value true is written

Is it possible to write other constant values to constant variables like in C ?

CodePudding user response:

Typing helps at compile time but not at runtime.

You can use this strategy at compile time to get the value safely:

type TrueType = true;
const myTrue: TrueType = true;
  • Related