HiveBrain v1.2.0
Get Started
← Back to all entries
snippettypescriptCritical

How to create enum like type in TypeScript?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
enumtypescripthowliketypecreate

Problem

I'm working on a definitions file for the Google maps API for TypeScript.

And I need to define an enum like type eg. google.maps.Animation which contains two properties: BOUNCE and DROP.

How should this be done in TypeScript?

Solution

TypeScript 0.9+ has a specification for enums:

enum AnimationType {
    BOUNCE,
    DROP,
}


The final comma is optional.

Code Snippets

enum AnimationType {
    BOUNCE,
    DROP,
}

Context

Stack Overflow Q#12687793, score: 176

Revisions (0)

No revisions yet.