0

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.

1

1 Answer 1

2

String literal types were added in TypeScript 1.8.

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

Sign up to request clarification or add additional context in comments.

1 Comment

forgot that my grunt-typescript plugin for grunt is using a lot older version of typescript :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.