How to Start TypeScript Numeric Enum From 1?

To start TypeScript numeric enum from 1 instead of the default 0, you simply need to specify 1 as the initializer for the first member in the enum. All members that follow are auto-incremented from that point on.

For example:

enum FooNum {
    A = 1,
    B,
    C,
}

console.log(FooNum.A); // 1
console.log(FooNum.B); // 2
console.log(FooNum.C); // 3

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.