Typescript typing constants
Let’s say you are creating a type and you want a property to refer to a specific constant.
a) Declare the constant
const MY_CONST = ‘MY_CONST’;
b) Use typeof to reference the constant.
type CustomType = {type: typeof MY_CONST, otherstuff: any}; Source: https://brudinie.medium.com/feed
Latest posts by ElearningWorld Admin (see all)
- Share Local Moodle Docker Using Ngrok – 23rd March 2024
- Moodle jobs: Moodle/Totara Engage LXP admin – Contract – Telecomute (office in Schaumburg, Illinois) – 21st March 2024
- Moodle Educator Certificate (MEC) starting 1st April – 8th March 2024