13

I am a typescript noob and javascript dummy so please be as explicit as possible without being too nerdy.

My basic understanding is Typescript gets precompiled into Javascript by a mystical being. The Javascript is then rendered by the browser. However, if that javascript is too advanced for the browser, you can use babel to stupify the javascript code into yet another Javascript version, like ES5 (which I heard Internet Explorer can now handle as of a couple weeks ago).

So question: What Javascript version does Typescript compile into? (ES6, ES5, etc?) How can I modify this as needed?

5
  • 7
    It defaults to ES3, but you can use the --target flag to specify a newer version, and some features will take advantage of that. Commented Jan 7, 2016 at 1:44
  • Thanks, where do I put the --target flag? Commented Jan 7, 2016 at 1:44
  • 5
    At command line tsc --target ES5 Commented Jan 7, 2016 at 2:16
  • why is ES3 the default? Commented Jan 7, 2016 at 2:33
  • 2
    @thedanotto Presumably because it's the most widely-supported version, being the oldest. They default to maximum practical compatibility (possibly at the expense of performance) and let people who know they don't need it opt-in to better less-compatible options. Commented Jan 7, 2016 at 3:55

1 Answer 1

12

You can specify the target ECMAScript version with the --target option.


Here is how you do it in Visual Studio.

... change TypeScriptTarget in the .csproj file ...

<TypeScriptTarget>ES5</TypeScriptTarget>


Here is how you do it from the command line. (notice that ES3 is the default)

+----------+-----------+---------------------------------------------+
| Option   | Shorthand |               Description                   |
+----------+-----------+---------------------------------------------+
| --target |    -t     | Specify ECMAScript target version: 'ES3'    |
|          |           | (default), 'ES5', or 'ES6'                  |
+----------+-----------+---------------------------------------------+
Sign up to request clarification or add additional context in comments.

1 Comment

Where I could find information about what I gain from targeting a newer version of ES? I'm assume changing the target version doesn't change things on the TypeScript side at all, so it must be purely for performance reasons.

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.