ducin
ducin

Reputation: 26477

TypeScript string-based enum compiler error

I want to create a string-based enum to represent Currencies in my system (USD, GBP, EUR, etc - such strings as the only allowed values).

I found exactly what I need in Basarat's TypeScript book. The thing is, when I try to use it as-is:

type CardinalDirection =
    "North"
    | "East"
    | "South"
    | "West";

I get a compiler error:

myfile.ts(4,5): error TS1110: Type expected.

I'm using tsc Version 1.5.0-beta. The question is: which versions do support this feature and/or how can I make it work?


edit: after upgrading tsc to 1.8.9 I get the same error.

Upvotes: 0

Views: 458

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 312095

String literal types were added in TypeScript 1.8.

Your code works fine in the TypeScript playground, so the syntax looks fine.

Upvotes: 2

Related Questions