V
V
Vasily2020-09-15 18:29:43
typescript
Vasily, 2020-09-15 18:29:43

What is the difference between type and enum?

What is the difference between writing

type Weekdays = "mon" | "tue" | "wed" | "thur" | "fri" | "sat" | "sun";

and
enum Weekdays {  "mon",  "tue",  "wed",  "thur",  "fri",  "sat",  "sun" }

Well, except that enum will compile to JS - an object, and type will only be available at compile time.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2020-09-15
@n_dufy

The fact that . If exactly lines are needed in enum, then exactly lines should be specified: Otherwise, this:Weekday2s.mon === 0enum Weekdays { mon = "mon", ...}

Well, except that enum will compile to JS - an object, and type will only be available at compile time.

more than enough. Instead of working with strings (new each time), you work with an object.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question