{"id":511,"date":"2015-11-30T12:48:00","date_gmt":"2015-11-30T12:48:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/typescript\/2015\/11\/30\/announcing-typescript-1-7\/"},"modified":"2019-02-20T10:46:08","modified_gmt":"2019-02-20T17:46:08","slug":"announcing-typescript-1-7","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/typescript\/announcing-typescript-1-7\/","title":{"rendered":"Announcing TypeScript 1.7"},"content":{"rendered":"<p>Today, we are thrilled to announce the release of TypeScript 1.7 along with the availability of <a href=\"http:\/\/blogs.msdn.com\/b\/visualstudio\/archive\/2015\/11\/30\/visual-studio-update-1-rtm.aspx\"><span style=\"color: #4078c0\">Visual Studio 2015 Update 1.<\/span><\/a> This release <a href=\"http:\/\/blogs.msdn.com\/b\/typescript\/archive\/2015\/11\/03\/what-about-async-await.aspx\"><span style=\"color: #4078c0\">enables async\/await by default for ECMAScript 6 (ES6) targets<\/span><\/a>. It also adds support for polymorphic &#8216;this&#8217; typing, proposed ECMAScript 2016 exponentiation syntax, and ES6 module targeting. For a complete change list, check out our <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/wiki\/Roadmap\"><span style=\"color: #4078c0\">roadmap<\/span><\/a> on GitHub.<\/p>\n<p>As always, you can get your hands on TypeScript 1.7 for <a title=\"http:\/\/go.microsoft.com\/fwlink\/?LinkId=691129\" href=\"https:\/\/www.visualstudio.com\/news\/vs2015-update1-vs\">Visual Studio 2015 Update 1<\/a>, <a href=\"http:\/\/download.microsoft.com\/download\/4\/4\/3\/443F86B7-A89F-48E6-AC96-0AAC2A910A29\/TS1.7.3-VSUOOB.41125.00\/TypeScript_Dev12.exe\"><span style=\"color: #4078c0\">Visual Studio 2013<\/span><\/a>, <a href=\"https:\/\/www.npmjs.com\/package\/typescript\"><span style=\"color: #4078c0\">on npm<\/span><\/a>, or straight from the <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/releases\"><span style=\"color: #4078c0\">source<\/span><\/a>.<\/p>\n<p><strong>Async\/Await for ES6 targets<\/strong><\/p>\n<p>With the 1.7 release, TypeScript now supports <a title=\"http:\/\/tc39.github.io\/ecmascript-asyncawait\/\" href=\"http:\/\/tc39.github.io\/ecmascript-asyncawait\/\">Async functions<\/a> for&nbsp;targets that have <a href=\"http:\/\/www.ecma-international.org\/ecma-262\/6.0\/#sec-generator-function-definitions\"><span style=\"color: #4078c0\">ES6 generator<\/span><\/a> support enabled (e.g. node.js v4 and above). Functions can now be prefixed with the <code>async<\/code> keyword designating it as an asynchronous function. The <code>await<\/code> keyword can then be used to stop execution until an <code>async<\/code> function&#8217;s promise is fulfilled. Following is a simple example:<\/p>\n<p><span style=\"font-family: courier new,courier\"><span style=\"color: #993300\">&#8220;use strict&#8221;<\/span>;<\/span><br><span style=\"color: #008000;font-family: courier new,courier\">\/\/ printDelayed is a &#8216;Promise&lt;void&gt;&#8217;<\/span><br><span style=\"font-family: courier new,courier\"><span style=\"color: #0000ff\">async function<\/span> printDelayed(elements: string[]) {<\/span><br><span style=\"font-family: courier new,courier\"><span style=\"color: #0000ff\">&nbsp;&nbsp;&nbsp; for<\/span> (<span style=\"color: #0000ff\">const<\/span> element <span style=\"color: #0000ff\">of<\/span> elements) {<\/span><br><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; await delay(200);<\/span><br><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; console.log(element);<\/span><br><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp; }<\/span><br><span style=\"font-family: courier new,courier\">}<\/span><br>&nbsp;<br><span style=\"font-family: courier new,courier\"><span style=\"color: #0000ff\">async function<\/span> delay(milliseconds: number) {<\/span><br><span style=\"font-family: courier new,courier\"><span style=\"color: #0000ff\">&nbsp;&nbsp;&nbsp; return<\/span> <span style=\"color: #0000ff\">new<\/span> Promise&lt;<span style=\"color: #0000ff\">void<\/span>&gt;(resolve =&gt; {<\/span><br><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setTimeout(resolve, milliseconds);<\/span><br><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp; });<\/span><br><span style=\"font-family: courier new,courier\">}<\/span><br>&nbsp;<br><span style=\"font-family: courier new,courier\">printDelayed([<span style=\"color: #993300\">&#8220;Hello&#8221;<\/span>, <span style=\"color: #993300\">&#8220;beautiful&#8221;<\/span>, <span style=\"color: #993300\">&#8220;asynchronous&#8221;<\/span>, <span style=\"color: #993300\">&#8220;world&#8221;<\/span>]).then(() =&gt; {<\/span><br><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp; console.log();<\/span><br><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp; console.log(<span style=\"color: #993300\">&#8220;Printed every element!&#8221;<\/span>);<\/span><br><span style=\"font-family: courier new,courier\">});<\/span><\/p>\n<p>We are working on bringing async\/await support in TypeScript for other targets, including a breadth of browsers, which might not have ES6 generators support. For more information on current implementation of async\/await and how to use it, see our <a href=\"http:\/\/blogs.msdn.com\/b\/typescript\/archive\/2015\/11\/03\/what-about-async-await.aspx\"><span style=\"color: #4078c0\">previous blog post<\/span><\/a>.<\/p>\n<p><strong>Polymorphic<em> this<\/em><\/strong><strong> Typing<\/strong><\/p>\n<p>After much <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/issues\/229\"><span style=\"color: #4078c0\">community discussion and feedback<\/span><\/a>, TypeScript 1.7 adds a new polymorphic this type. A this type can be used in classes and interfaces to represent <em>some type that is a subtype of the containing type<\/em> (rather than the containing type itself). This feature makes patterns such as hierarchical fluent APIs much easier to express.<\/p>\n<p><span style=\"font-family: courier new,courier\"><span style=\"color: #0000ff\">interface<\/span> Model {<\/span><br><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp; setupBase(): <span style=\"color: #0000ff\">this<\/span>;<\/span><br><span style=\"font-family: courier new,courier\">}<\/span><br>&nbsp;<br><span style=\"font-family: courier new,courier\"><span style=\"color: #0000ff\">interface<\/span> AdvancedModel extends Model {<\/span><br><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp; setupAdvanced(): <span style=\"color: #0000ff\">this<\/span>;<\/span><br><span style=\"font-family: courier new,courier\">}<\/span><br>&nbsp;<br><span style=\"font-family: courier new,courier\"><span style=\"color: #0000ff\">declare function<\/span> createModel(): AdvancedModel;<\/span><br><span style=\"font-family: courier new,courier\">newModel = newModel.setupBase().setupAdvanced(); <span style=\"color: #008000\">\/\/ fluent style works<\/span><\/span><\/p>\n<p>For a deep dive on this typing, checkout the <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/wiki\/What%27s-new-in-TypeScript#this-typing\"><span style=\"color: #4078c0\">TypeScript Wiki<\/span><\/a>.<\/p>\n<p>As a part of supporting the feature, TypeScript 1.7 has made changes in inferring the type from this. In a class, the type of the value this will be inferred to the this type, and subsequent assignments from values of the original type can fail. As a workaround, you could add a type annotation for this. A code sample with recommended work around, along with a list of other <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/wiki\/Breaking-Changes#TypeScript1.7\"><span style=\"color: #4078c0\">potentially breaking changes<\/span><\/a> is available at GitHub.<\/p>\n<p><strong>ES6 Module Emitting<\/strong><\/p>\n<p>TypeScript 1.7 adds es6 to the list of options available for the &#8211;module flag and allows you to specify the module output when targeting ES6. This provides more flexibility to target exactly the features you want in specific runtimes. For example, it is now a breeze to target Node.js v4 and beyond, which doesn&#8217;t support ES6 modules (but does support several other ES6 features).<\/p>\n<p><span style=\"color: #993300;font-family: courier new,courier\">\/\/tsconfig.json targeting node.js v4 and beyond<\/span><br><span style=\"font-family: courier new,courier\">{<\/span><br><span style=\"font-family: courier new,courier\"><span style=\"color: #993300\">&nbsp;&nbsp;&nbsp; &#8220;compilerOptions&#8221;<\/span>: {<\/span><br><span style=\"font-family: courier new,courier\"><span style=\"color: #993300\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;module&#8221;<\/span>: <span style=\"color: #993300\">&#8220;commonjs&#8221;<\/span>,<\/span><br><span style=\"font-family: courier new,courier\"><span style=\"color: #993300\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;target&#8221;<\/span>: <span style=\"color: #993300\">&#8220;es6&#8221;<\/span><\/span><br><span style=\"font-family: courier new,courier\">&nbsp;&nbsp;&nbsp; }<\/span><br><span style=\"font-family: courier new,courier\">}<\/span><\/p>\n<p><strong>ES7 Exponentiation<\/strong><\/p>\n<p>Finally, a little syntactic sugar! The ECMAScript committee recently moved the <a href=\"https:\/\/github.com\/rwaldron\/exponentiation-operator\"><span style=\"color: #4078c0\">Exponentiation Operator proposal<\/span><\/a> to <a href=\"https:\/\/tc39.github.io\/process-document\/\"><span style=\"color: #4078c0\">stage 3<\/span><\/a>. So we decided it was ready for TypeScript to adopt, and added support for it in TypeScript 1.7.<\/p>\n<div><span style=\"font-family: courier new,courier\"><span style=\"color: #0000ff\">let<\/span> squared = 2 ** 2;&nbsp; <span style=\"color: #008000\">\/\/ same as: 2 * 2<\/span><\/span><br><span style=\"font-family: courier new,courier\"><span style=\"color: #0000ff\">let<\/span> cubed = 2 ** 3;&nbsp; <span style=\"color: #008000\">\/\/ same as: 2 * 2 * 2<\/span><\/span><\/div>\n<div><span style=\"font-family: courier new,courier\"><span style=\"color: #0000ff\">let<\/span> num = 2;<\/span><br><span style=\"font-family: courier new,courier\">num **= 2; <span style=\"color: #008000\">\/\/ same as: num = num * num;<\/span><\/span><\/div>\n<p>Say goodbye to <span style=\"font-family: courier new,courier\">Math.pow()<\/span>!<\/p>\n<p><strong>What&#8217;s Next?<\/strong><\/p>\n<p>We are excited to announce all the new improvements we&#8217;ve made in this release, and as always, we would love to hear your feedback. Everything we do is easily viewable on our <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\"><span style=\"color: #4078c0\">Github<\/span><\/a>. If you&#8217;re interested in weighing in on the future of TypeScript, we encourage you to check out our existing <a href=\"https:\/\/github.com\/microsoft\/typescript\/issues\"><span style=\"color: #4078c0\">issues<\/span><\/a>, throw us a <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/pulls\"><span style=\"color: #4078c0\">pull request<\/span><\/a>, or just come hang out with the team on <a href=\"https:\/\/gitter.im\/Microsoft\/TypeScript\"><span style=\"color: #4078c0\">gitter<\/span><\/a>.<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, we are thrilled to announce the release of TypeScript 1.7 along with the availability of Visual Studio 2015 Update 1. This release enables async\/await by default for ECMAScript 6 (ES6) targets. It also adds support for polymorphic &#8216;this&#8217; typing, proposed ECMAScript 2016 exponentiation syntax, and ES6 module targeting. For a complete change list, check [&hellip;]<\/p>\n","protected":false},"author":379,"featured_media":1797,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-511","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-typescript"],"acf":[],"blog_post_summary":"<p>Today, we are thrilled to announce the release of TypeScript 1.7 along with the availability of Visual Studio 2015 Update 1. This release enables async\/await by default for ECMAScript 6 (ES6) targets. It also adds support for polymorphic &#8216;this&#8217; typing, proposed ECMAScript 2016 exponentiation syntax, and ES6 module targeting. For a complete change list, check [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts\/511","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/users\/379"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/comments?post=511"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts\/511\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/media\/1797"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/media?parent=511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/categories?post=511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/tags?post=511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}