In another way :
How would you introduce the windowState DOM property in TypeScript?
SOLVED (in TypeScript 2):
declare var windowState: WindowState const enum WindowState { STATE_MAXIMIZED = 1, STATE_MINIMIZED = 2, STATE_NORMAL = 3, STATE_FULLSCREEN = 4 } ... var windowState = 5 // Type Error, as expected!
The original question :
How to declare a type in TypeScript to describe the type of algebraic data? The purpose of this is to describe the existing API.
When I try to do the following, TypeScript obviously complains that type is expected :
type Weather = 'sunny' | 'bad'
One of my ideas is to use the JavaScript 2015 Symbol , however TypeScript doesn't seem to know about this.
Another idea was to use enum , however TypeScript complains that a member initializer must be constant expression :
const enum Weather { sunny = 'sunny', bad = 'bad', windy = Symbol('windy') }
I would think that the string constant is a constant expression.
source share