{"id":461,"date":"2015-09-02T13:00:00","date_gmt":"2015-09-02T13:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/typescript\/2015\/09\/02\/announcing-typescript-1-6-beta-reactjsx-better-error-checking-and-more\/"},"modified":"2024-07-02T10:14:56","modified_gmt":"2024-07-02T18:14:56","slug":"announcing-typescript-1-6-beta-reactjsx-better-error-checking-and-more","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/typescript\/announcing-typescript-1-6-beta-reactjsx-better-error-checking-and-more\/","title":{"rendered":"Announcing TypeScript 1.6 Beta: React\/JSX, better error checking, and more"},"content":{"rendered":"<p>Today, we\u2019re making a beta of the upcoming TypeScript 1.6 available. \u00a0There are a <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/wiki\/Roadmap\">bunch of new features<\/a> coming in the 1.6 release, and we wanted to give you a preview of these features and time to give us <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/issues\">feedback<\/a>.<\/p>\n<p>You can get this for <a href=\"http:\/\/download.microsoft.com\/download\/6\/D\/8\/6D8381B0-03C1-4BD2-AE65-30FF0A4C62DA\/TS1.6-Beta-D14OOB.23301.00\/TypeScript_Full.exe\">Visual Studio 2015<\/a>, <a href=\"http:\/\/download.microsoft.com\/download\/4\/4\/3\/443F86B7-A89F-48E6-AC96-0AAC2A910A29\/TS1.6-Beta-VUOOB.40831.00\/TypeScript_Dev12.exe\">Visual Studio 2013<\/a>, <a href=\"https:\/\/www.npmjs.com\/package\/typescript\">NPM<\/a>, and <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/releases\/tag\/v1.6.0-beta\">source<\/a>.<\/p>\n<h2>React\/JSX support<\/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>One of the key philosophies of TypeScript is to let you write TypeScript anywhere you can develop using JavaScript.\u00a0 While we\u2019ve worked with teams such as Dojo, Aurelia, and Angular to ensure using TypeScript is as easy as using JavaScript, there was still an important library that that presented a\u00a0<a href=\"https:\/\/www.youtube.com\/watch?v=9PTa9-PPVAc\">difficulty<\/a>\u00a0for TypeScript developers: React.\u00a0 This was due to the lack of support for JSX, a popular way of writing DOM and native components in JS.\u00a0 React heavily leverages JSX in everyday code.\u00a0 Unfortunately, the syntax for JSX conflicted with the cast syntax that TypeScript already used.<\/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><em>Refactoring JSX members in TypeScript (click to watch animation)\n<\/em><\/p>\n<p>In 1.6, we\u2019ve introduced a <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/pull\/3564\">new .tsx file extension<\/a>.\u00a0 This extension does two things: it enables JSX inside of TypeScript files, and it makes the new \u2018as\u2019 operator the default way to cast.\u00a0 With this, we\u2019ve added full support for working with React\/JSX in TypeScript in a type-safe way.<\/p>\n<h2>Catching more errors<\/h2>\n<p>Starting with 1.6, we\u2019re tightening up some of our object checking rules.\u00a0 In the beta, you\u2019ll see that objects need to <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/pull\/3823\">match more closely when they are assigned<\/a>.\u00a0 For example:<\/p>\n<p><span style=\"font-family: courier new,courier;\"><span style=\"color: #0000ff;\">var<\/span> x: { foo: <span style=\"color: #0000ff;\">number<\/span> };<\/span>\n<span style=\"font-family: courier new,courier;\">x = { foo: 1, baz: 2 };\u00a0 <span style=\"color: #008000;\">\/\/ Error, excess property &#8216;baz&#8217;, but not caught before 1.6<\/span><\/span><\/p>\n<p><span style=\"font-family: courier new,courier;\"><span style=\"color: #0000ff;\">var<\/span> y: { foo: <span style=\"color: #0000ff;\">number<\/span>, bar?: <span style=\"color: #0000ff;\">number<\/span> };<\/span>\n<span style=\"font-family: courier new,courier;\">y = { foo: 1, baz: 2 };\u00a0 <span style=\"color: #008000;\">\/\/ Error, excess or misspelled property &#8216;baz&#8217;, also not caught before 1.6<\/span><\/span><\/p>\n<p>When fields are optional, it\u2019s easy to accidentally pass mistyped fields or miss when a refactoring has left excess fields.\u00a0 This change has already helped to find dozens (if not hundreds) of real-world bugs in early adopter code.\u00a0 As part of this change, we found <a href=\"https:\/\/github.com\/borisyankov\/DefinitelyTyped\/pull\/5151\">bugs in DefinitelyTyped<\/a> (including the tests that are used to validate the hand-written .d.ts files):<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2015\/09\/4722.definitelytyped_fixes.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-4344\" src=\"https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2015\/09\/4722.definitelytyped_fixes.png\" alt=\"Image 4722 definitelytyped fixes\" width=\"687\" height=\"506\" srcset=\"https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2015\/09\/4722.definitelytyped_fixes.png 687w, https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2015\/09\/4722.definitelytyped_fixes-300x221.png 300w\" sizes=\"(max-width: 687px) 100vw, 687px\" \/><\/a><\/p>\n<p><em>Examples of the errors caught with the new rules<\/em><\/p>\n<p>While this change may show where bugs have been hiding previously, you may not be ready to tackle a new set of compiler errors in your existing code right away, or you may not want to change the way your code behaves. \u00a0There\u2019s a <a href=\"http:\/\/stackoverflow.com\/questions\/31816061\/why-am-i-getting-an-error-object-literal-may-only-specify-known-properties\">good list<\/a> of ways to work around this assignment check, depending on the capability you want your code to have.<\/p>\n<p><strong>EDIT: <\/strong>You can also suppress this warning by passing the <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/pull\/4484\">&#8211;suppressExcessPropertyErrors<\/a>\u00a0compiler option.<\/p>\n<h2>Improved module resolution<\/h2>\n<p>Previously, TypeScript used a hybrid approach for resolving both CommonJS and RequireJS.\u00a0 Unfortunately, this meant that module resolution didn\u2019t feel at home in either style, and instead made you structure projects in a way that didn\u2019t feel natural for that particular module loader.<\/p>\n<p>We\u2019re working on a <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/issues\/2338\">set of improvements<\/a> to make module resolution more natural.\u00a0 In the 1.6 beta, you\u2019ll see the start of that work.\u00a0 We invite you to <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/issues\/2338\">read more<\/a> on what we\u2019re working on and send us your <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/issues\/2338\">feedback<\/a>.<\/p>\n<h2>And more<\/h2>\n<p>We\u2019ve continued to improve ES6 support with added support for <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/issues\/497\">class expressions<\/a> and the start of support for <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/issues\/2873\">generators<\/a>.\u00a0 You can see the full list of new features on our <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/wiki\/Roadmap\">roadmap<\/a>.\u00a0 We\u2019d love to hear your <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/issues\/2873\">feedback<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, we\u2019re making a beta of the upcoming TypeScript 1.6 available. \u00a0There are a bunch of new features coming in the 1.6 release, and we wanted to give you a preview of these features and time to give us feedback. You can get this for Visual Studio 2015, Visual Studio 2013, NPM, and source. React\/JSX [&hellip;]<\/p>\n","protected":false},"author":377,"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-461","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-typescript"],"acf":[],"blog_post_summary":"<p>Today, we\u2019re making a beta of the upcoming TypeScript 1.6 available. \u00a0There are a bunch of new features coming in the 1.6 release, and we wanted to give you a preview of these features and time to give us feedback. You can get this for Visual Studio 2015, Visual Studio 2013, NPM, and source. React\/JSX [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts\/461","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\/377"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/comments?post=461"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts\/461\/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=461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/categories?post=461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/tags?post=461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}