Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Differences between interfaces, types and enumerations in TS
Differences between interfaces, types and enumerations in TS
In TypeScript, we use interfaces to define the types of objects.

In object-oriented language, interface is a very important concept, which is an abstraction of behavior, and how to operate it needs to be realized through classes.

For example:

Type aliases are used to provide a new name for the type.

Or use the literal type of a string to limit the value to only one of several strings.

Therefore, type aliases are usually used for joint types.

For example:

Enum type is used in scenes with limited values, such as only seven days in a week, and the colors are limited to red, green and blue.

Enumeration members are given numbers that increase from 0, and enumeration values are inversely mapped to enumeration names:

You can also assign values manually: