{"id":1675,"date":"2015-09-16T13:00:00","date_gmt":"2015-09-16T13:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/typescript\/2015\/09\/16\/announcing-typescript-1-6\/"},"modified":"2024-07-02T12:06:58","modified_gmt":"2024-07-02T20:06:58","slug":"announcing-typescript-1-6-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/typescript\/announcing-typescript-1-6-2\/","title":{"rendered":"Announcing TypeScript 1.6"},"content":{"rendered":"<p>Today, we&#8217;re happy to announce the release of TypeScript 1.6. \u00a0This release adds support\u00a0for React\/JSX, class expressions, and a rich set of new capabilities in the type system. It also provides stricter type checking for object literals.<\/p>\n<p>You can download\u00a0TypeScript 1.6 for <a title=\"TypeScript 1.6 for VS2015\" href=\"http:\/\/download.microsoft.com\/download\/6\/D\/8\/6D8381B0-03C1-4BD2-AE65-30FF0A4C62DA\/TS1.6.2-D14OOB.23313.00\/TypeScript_Full.exe\">Visual Studio 2015<\/a>, <a title=\"TypeScript 1.6 for VS2013\" href=\"http:\/\/download.microsoft.com\/download\/4\/4\/3\/443F86B7-A89F-48E6-AC96-0AAC2A910A29\/TS1.6.2-VUOOB.40914.00\/TypeScript_Dev12.exe\">Visual Studio 2013<\/a>, on <a title=\"TypeScript npm package\" href=\"https:\/\/www.npmjs.com\/package\/typescript\">npm<\/a>, or as <a title=\"TypeScript 1.6 source code\" href=\"https:\/\/github.com\/Microsoft\/TypeScript\/releases\/tag\/v1.6.2\">source<\/a>.<\/p>\n<h2>React\/JSX<\/h2>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2015\/09\/8512.react_.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-4341\" src=\"https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2015\/09\/8512.react_-300x268.png\" alt=\"Image 8512 react\" width=\"300\" height=\"268\" srcset=\"https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2015\/09\/8512.react_-300x268.png 300w, https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2015\/09\/8512.react_.png 570w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Designed with feedback from React experts and the React team, we&#8217;ve built full-featured support for React typing and the JSX support in React. \u00a0Below, you can see TypeScript code happily coexisting with JSX syntax within a single file with the new .tsx extension. This allows React developers to intermingle HTML-like syntax with TypeScript code.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2015\/09\/6177.Renaming.gif\"><img decoding=\"async\" class=\"alignnone size-full wp-image-4343\" src=\"https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2015\/09\/6177.Renaming.gif\" alt=\"Image 6177 Renaming\" width=\"760\" height=\"257\" \/><\/a><\/p>\n<p>Our goal was to make it feel natural to work with React\/JSX and to have all the type-checking and autocomplete\u00a0capabilities of TypeScript. \u00a0This allows you a rich editing experience for working with React and JSX when using VS, VS Code, and Sublime.<\/p>\n<h2>Class expressions<\/h2>\n<p>This release also makes it possible to write class expressions, as we continue to round out the ES6 support in TypeScript. \u00a0Similar to class declarations, class expressions allow you to create new classes.\u00a0 Unlike class declarations, you can use class expressions wherever you use an expression.\u00a0 For example, you can now create a class and use it in your <span style=\"font-family: 'courier new', courier;\">extends<\/span> clause.<\/p>\n<p><span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">class<\/span> StateHandler <span style=\"color: #0000ff;\">extends<\/span> class { reset() { <span style=\"color: #0000ff;\">return<\/span> <span style=\"color: #0000ff;\">true<\/span>; } } {\nconstructor() {<\/span>\n<span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">\u00a0 \u00a0 \u00a0super<\/span>();<\/span>\n<span style=\"font-family: 'courier new', courier;\">\u00a0 \u00a0}<\/span>\n<span style=\"font-family: 'courier new', courier;\">}<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">var<\/span> g = <span style=\"color: #0000ff;\">new<\/span> StateHandler();<\/span>\n<span style=\"font-family: 'courier new', courier;\">g.reset();<\/span><\/p>\n<p>This class can be anonymous and still has all the same capabilities of class declarations.<\/p>\n<h2>User defined type guards<\/h2>\n<p>In earlier versions of TypeScript, you could use <span style=\"font-family: 'courier new', courier;\">if\u00a0<\/span>statements to narrow the type. For example, you could use:<\/p>\n<p><span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">if<\/span> (<span style=\"color: #0000ff;\">typeof<\/span> x === <span style=\"color: #800000;\">&#8220;number&#8221;<\/span>) { \u2026 }<\/span><\/p>\n<p>This helped type information flow into common ways of working with types at runtime (inspired by some of the other projects doing typechecking of JS). While this approach is powerful, we wanted to push it a bit further.\u00a0 In 1.6, you can now create your own type guard functions:<\/p>\n<p><span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">interface<\/span> Animal {name: <span style=\"color: #0000ff;\">string<\/span>; }\n<span style=\"color: #0000ff;\">interface<\/span> Cat <span style=\"color: #0000ff;\">extends<\/span> Animal { meow(); }<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">function<\/span> isCat(a: Animal): a <span style=\"color: #0000ff;\">is<\/span> Cat {<\/span>\n<span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">\u00a0 return<\/span> a.name === <span style=\"color: #800000;\">&#8216;kitty&#8217;<\/span>;<\/span>\n<span style=\"font-family: 'courier new', courier;\">}<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">var<\/span> x: Animal;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">if<\/span>(isCat(x)) {<\/span>\n<span style=\"font-family: 'courier new', courier;\">\u00a0 x.meow(); <span style=\"color: #008000;\">\/\/ OK, x is Cat in this block<\/span><\/span>\n<span style=\"font-family: 'courier new', courier;\">}<\/span><\/p>\n<p>This allows you to work with not only <span style=\"font-family: 'courier new', courier;\">typeof<\/span> and <span style=\"font-family: 'courier new', courier;\">instanceof<\/span> checks, which need a type that JavaScript understands, but now you can work with interfaces and do custom analysis.\u00a0 Guard functions are denoted by their \u201c<span style=\"font-family: 'courier new', courier;\">a is X<\/span>\u201d return type, which returns boolean and signals to the compiler if what the expected type now is.<\/p>\n<h2>Intersection types<\/h2>\n<p>Common patterns in JS that haven\u2019t been easy to express in TypeScript are mixins and extending existing classes with new methods.\u00a0 To help with this, we\u2019re adding a new type operator \u2018&amp;\u2019 that will combine two types together.\u00a0 While it was possible to do this before by creating a new interface that inherited from two other types, this tended to be clunky and couldn\u2019t be used in the case you wanted to use it most: combining generic types.<\/p>\n<p>This new &amp; operator, called intersection, creates anonymous combinations of types.<\/p>\n<p><span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">function<\/span> extend&lt;T, U&gt;(first: T, second: U): T &amp; U {<\/span>\n<span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">\u00a0 let<\/span> result = &lt;T &amp; U&gt; {};<\/span>\n<span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">\u00a0 for<\/span> (<span style=\"color: #0000ff;\">let<\/span> id <span style=\"color: #0000ff;\">in<\/span> first) {<\/span>\n<span style=\"font-family: 'courier new', courier;\">\u00a0 \u00a0 result[id] = first[id];<\/span>\n<span style=\"font-family: 'courier new', courier;\">\u00a0 }<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">\u00a0 for<\/span> (<span style=\"color: #0000ff;\">let<\/span> id <span style=\"color: #0000ff;\">in<\/span> second) {<\/span>\n<span style=\"font-family: 'courier new', courier;\">\u00a0 \u00a0 if (!result.hasOwnProperty(id)) {<\/span>\n<span style=\"font-family: 'courier new', courier;\">\u00a0 \u00a0 \u00a0 result[id] = second[id];<\/span>\n<span style=\"font-family: 'courier new', courier;\">\u00a0 \u00a0 }<\/span>\n<span style=\"font-family: 'courier new', courier;\">\u00a0 }<\/span>\n<span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">\u00a0 return<\/span> result;<\/span>\n<span style=\"font-family: 'courier new', courier;\">}<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">var<\/span> x = extend({ a: <span style=\"color: #800000;\">&#8220;hello&#8221;<\/span> }, { b: 42 });<\/span>\n<span style=\"font-family: 'courier new', courier;\">x.a; <span style=\"color: #008000;\">\/\/ works<\/span><\/span>\n<span style=\"font-family: 'courier new', courier;\">x.b; <span style=\"color: #008000;\">\/\/ works\u00a0<\/span><\/span><\/p>\n<div>\n<h2>Abstract classes<\/h2>\n<p>A <a href=\"http:\/\/typescript.codeplex.com\/workitem\/list\/basic?field=Votes&amp;direction=Descending&amp;issuesToDisplay=All&amp;keywords=&amp;emailSubscribedItemsOnly=false\">long-standing feature request<\/a> for TypeScript has been supporting abstract classes.\u00a0 Similar in some ways to interfaces, abstract classes give you a way of creating a base class, complete with default implementations, that you can build from with the intention of it never being used directly outside of the class hierarchy.<\/p>\n<p><span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">abstract<\/span> <span style=\"color: #0000ff;\">class<\/span> A {\nfoo(): <span style=\"color: #0000ff;\">number<\/span> { <span style=\"color: #0000ff;\">return<\/span> this.bar(); }<\/span>\n<span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">\u00a0 abstract<\/span> bar(): <span style=\"color: #0000ff;\">number<\/span>;<\/span>\n<span style=\"font-family: 'courier new', courier;\">}<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">var<\/span> a = <span style=\"color: #0000ff;\">new<\/span> A();\u00a0 <span style=\"color: #008000;\">\/\/ error, Cannot create an instance of the abstract class &#8216;A&#8217;<\/span><\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">class<\/span> B <span style=\"color: #0000ff;\">extends<\/span> A {\nbar() { <span style=\"color: #0000ff;\">return<\/span> 1; }<\/span>\n<span style=\"font-family: 'courier new', courier;\">}<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">var<\/span> b = <span style=\"color: #0000ff;\">new<\/span>\u00a0B();\u00a0 <span style=\"color: #008000;\">\/\/ success, all abstracts are defined<\/span><\/span><\/p>\n<h2>Generic type aliases<\/h2>\n<p>Leading up to TypeScript 1.6, type aliases were restricted to being simple aliases that shortened long type names.\u00a0 Unfortunately, without being able to make these generic, they had limited use.\u00a0 We now allow type aliases to be generic, giving them full expressive capability.<\/p>\n<p><span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">type<\/span> switcharoo&lt;T, U&gt; = (u: U, t:T)=&gt;T;<\/span>\n<span style=\"font-family: 'courier new', courier;\"><span style=\"color: #0000ff;\">var<\/span> f: switcharoo&lt;<span style=\"color: #0000ff;\">number<\/span>, <span style=\"color: #0000ff;\">string<\/span>&gt;;<\/span>\n<span style=\"font-family: 'courier new', courier;\">f(<span style=\"color: #800000;\">&#8220;bob&#8221;<\/span>, 4);<\/span><\/p>\n<h2>Potentially-breaking changes<\/h2>\n<p>Along with all the new features, we also spent some time tightening and fixing up a few areas of the system to generally work better, help you catch more errors, and be closer to how other tools work.\u00a0 In this release we now require\u00a0that an object literal should be matched directly.\u00a0 We\u2019ve also updated the module resolution logic to work more closely to what you would expect for the type of output module you selected.\u00a0 You can read the <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/wiki\/Breaking-Changes\">full list of potential breaking changes<\/a> with their mitigations.<\/p>\n<h2>Object literal strictness<\/h2>\n<p>We\u2019ve made object compatibility stricter to help catch a class of common bugs.\u00a0 You can learn more about this in the <a href=\"http:\/\/blogs.msdn.com\/b\/typescript\/archive\/2015\/09\/02\/announcing-typescript-1-6-beta-react-jsx-better-error-checking-and-more.aspx\">1.6 beta post<\/a>.<\/p>\n<h2>Improvements to module resolution<\/h2>\n<p>We\u2019ve changed module resolution when doing CommonJS output to work more closely to how Node does module resolution.\u00a0 If a module name is non-relative, we now follow these steps to find the associated typings:<\/p>\n<ol>\n<li>Check in <span style=\"font-family: 'courier new', courier;\">node_modules<\/span> for<span style=\"font-family: 'courier new', courier;\"> &lt;module name&gt;.d.ts<\/span><\/li>\n<li>Search <span style=\"font-family: 'courier new', courier;\">node_modules\\&lt;module name&gt;\\package.json<\/span> for a typings field<\/li>\n<li>Look for <span style=\"font-family: 'courier new', courier;\">node_modules\\&lt;module name&gt;\\index.d.ts<\/span><\/li>\n<li>Then we go one level higher and repeat the process<\/li>\n<\/ol>\n<p><strong>Please note<\/strong>: when we search through node_modules, we assume these are the packaged node modules which have type information and a corresponding .js file. \u00a0As such, we resolve only .d.ts files (not .ts file) for non-relative names.<\/p>\n<p>Previously, we \u00a0treated all module names as relative paths, and therefore we would never properly look in node_modules.\u00a0 If you prefer the previous behavior, you can use the compiler flag \u201c&#8211;moduleResolution classic\u201d.\u00a0 We will continue to improve module resolution, including improvements to AMD, in upcoming releases.<\/p>\n<h2>Looking ahead<\/h2>\n<p>We\u2019re excited to reveal all the new improvements to TypeScript and to hear your <a href=\"https:\/\/github.com\/microsoft\/typescript\/issues\">feedback<\/a>.\u00a0 There\u2019s lots to come, with more ES6 and ES7 features ahead.\u00a0 And we\u2019re always open if you want to <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/pulls\">jump in<\/a>.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Today, we&#8217;re happy to announce the release of TypeScript 1.6. \u00a0This release adds support\u00a0for React\/JSX, class expressions, and a rich set of new capabilities in the type system. It also provides stricter type checking for object literals. You can download\u00a0TypeScript 1.6 for Visual Studio 2015, Visual Studio 2013, on npm, or as source. React\/JSX Designed [&hellip;]<\/p>\n","protected":false},"author":375,"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-1675","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-typescript"],"acf":[],"blog_post_summary":"<p>Today, we&#8217;re happy to announce the release of TypeScript 1.6. \u00a0This release adds support\u00a0for React\/JSX, class expressions, and a rich set of new capabilities in the type system. It also provides stricter type checking for object literals. You can download\u00a0TypeScript 1.6 for Visual Studio 2015, Visual Studio 2013, on npm, or as source. React\/JSX Designed [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts\/1675","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\/375"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/comments?post=1675"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts\/1675\/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=1675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/categories?post=1675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/tags?post=1675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}