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)
- Moodle jobs: Full-time eLearning Consultant – Full-time – Telecommute – 20th January 2025
- Moodle jobs: Moodle UX/UI designer – Contract – Remote – 7th December 2024
- PHP 8.0 Model Classes with constructor promotion – 24th November 2024