{"id":4935,"date":"2025-07-08T09:38:54","date_gmt":"2025-07-08T17:38:54","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/typescript\/?p=4935"},"modified":"2025-07-09T17:45:45","modified_gmt":"2025-07-10T01:45:45","slug":"announcing-typescript-5-9-beta","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/typescript\/announcing-typescript-5-9-beta\/","title":{"rendered":"Announcing TypeScript 5.9 Beta"},"content":{"rendered":"<p>Today we are excited to announce the availability of TypeScript 5.9 Beta.<\/p>\n<p>To get started using the beta, you can get it through npm with the following command:<\/p>\n<pre class=\"prettyprint language-sh\" style=\"padding: 10px; border-radius: 10px;\"><code>npm install -D typescript@beta\r\n<\/code><\/pre>\n<p>Let&#8217;s take a look at what&#8217;s new in TypeScript 5.9!<\/p>\n<ul>\n<li><a href=\"#minimal-and-updated-tsc---init\">Minimal and Updated <code>tsc --init<\/code><\/a><\/li>\n<li><a href=\"#support-for-import-defer\">Support for <code>import defer<\/code><\/a><\/li>\n<li><a href=\"#support-for---module-node20\">Support for <code>--module node20<\/code><\/a><\/li>\n<li><a href=\"#summary-descriptions-in-dom-apis\">Summary Descriptions in DOM APIs<\/a><\/li>\n<li><a href=\"#expandable-hovers-preview\">Expandable Hovers (Preview)<\/a><\/li>\n<li><a href=\"#configurable-maximum-hover-length\">Configurable Maximum Hover Length<\/a><\/li>\n<li><a href=\"#optimizations\">Optimizations<\/a><\/li>\n<\/ul>\n<h2 id=\"minimal-and-updated-tsc---init\">Minimal and Updated <code>tsc --init<\/code><\/h2>\n<p>For a while, the TypeScript compiler has supported an <code>--init<\/code> flag that can create a <code>tsconfig.json<\/code> within the current directory.\nIn the last few years, running <code>tsc --init<\/code> created a very &#8220;full&#8221; <code>tsconfig.json<\/code>, filled with commented-out settings and their descriptions.\nWe designed this with the intent of making options discoverable and easy to toggle.<\/p>\n<p>However, given external feedback (and our own experience), we found it&#8217;s common to immediately delete most of the contents of these new <code>tsconfig.json<\/code> files.\nWhen users want to discover new options, we find they rely on auto-complete from their editor, or navigate to <a href=\"https:\/\/www.typescriptlang.org\/tsconfig\/\">the tsconfig reference on our website<\/a> (which the generated <code>tsconfig.json<\/code> links to!).\nWhat each setting does is also documented on that same page, and can be seen via editor hovers\/tooltips\/quick info.\nWhile surfacing some commented-out settings might be helpful, the generated <code>tsconfig.json<\/code> was often considered overkill.<\/p>\n<p>We also felt that it was time that <code>tsc --init<\/code> initialized with a few more prescriptive settings than we already enable.\nWe looked at some common pain points and papercuts users have when they create a new TypeScript project.\nFor example, most users write in modules (not global scripts), and <code>--moduleDetection<\/code> can force TypeScript to treat every implementation file as a module.\nDevelopers also often want to use the latest ECMAScript features directly in their runtime, so <code>--target<\/code> can typically be set to <code>esnext<\/code>.\nJSX users often find that going back to set <code>--jsx<\/code> is a needless friction, and its options are slightly confusing.\nAnd often, projects end up loading more declaration files from <code>node_modules\/@types<\/code> than TypeScript actually needs &#8211; but specifying an empty <code>types<\/code> array can help limit this.<\/p>\n<p>In TypeScript 5.9, a plain <code>tsc --init<\/code> with no other flags will generate the following <code>tsconfig.json<\/code>:<\/p>\n<pre class=\"prettyprint language-json\" style=\"padding: 10px; border-radius: 10px;\"><code>{\r\n  \/\/ Visit https:\/\/aka.ms\/tsconfig to read more about this file\r\n  \"compilerOptions\": {\r\n    \/\/ File Layout\r\n    \/\/ \"rootDir\": \".\/src\",\r\n    \/\/ \"outDir\": \".\/dist\",\r\n\r\n    \/\/ Environment Settings\r\n    \/\/ See also https:\/\/aka.ms\/tsconfig_modules\r\n    \"module\": \"nodenext\",\r\n    \"target\": \"esnext\",\r\n    \"types\": [],\r\n    \/\/ For nodejs:\r\n    \/\/ \"lib\": [\"esnext\"],\r\n    \/\/ \"types\": [\"node\"],\r\n    \/\/ and npm install -D @types\/node\r\n\r\n    \/\/ Other Outputs\r\n    \"sourceMap\": true,\r\n    \"declaration\": true,\r\n    \"declarationMap\": true,\r\n\r\n    \/\/ Stricter Typechecking Options\r\n    \"noUncheckedIndexedAccess\": true,\r\n    \"exactOptionalPropertyTypes\": true,\r\n\r\n    \/\/ Style Options\r\n    \/\/ \"noImplicitReturns\": true,\r\n    \/\/ \"noImplicitOverride\": true,\r\n    \/\/ \"noUnusedLocals\": true,\r\n    \/\/ \"noUnusedParameters\": true,\r\n    \/\/ \"noFallthroughCasesInSwitch\": true,\r\n    \/\/ \"noPropertyAccessFromIndexSignature\": true,\r\n\r\n    \/\/ Recommended Options\r\n    \"strict\": true,\r\n    \"jsx\": \"react-jsx\",\r\n    \"verbatimModuleSyntax\": true,\r\n    \"isolatedModules\": true,\r\n    \"noUncheckedSideEffectImports\": true,\r\n    \"moduleDetection\": \"force\",\r\n    \"skipLibCheck\": true,\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>For more details, see the <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/61813\">implementing pull request<\/a> and <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/issues\/58420\">discussion issue<\/a>.<\/p>\n<h2 id=\"support-for-import-defer\">Support for <code>import defer<\/code><\/h2>\n<p>TypeScript 5.9 introduces support for <a href=\"https:\/\/github.com\/tc39\/proposal-defer-import-eval\/\">ECMAScript&#8217;s deferred module evaluation proposal<\/a> using the new <code>import defer<\/code> syntax.\nThis feature allows you to import a module without immediately executing the module and its dependencies, providing better control over when work and side-effects occur.<\/p>\n<p>The syntax only permits namespace imports:<\/p>\n<pre class=\"prettyprint language-typescript\" style=\"padding: 10px; border-radius: 10px;\"><code>import defer * as feature from \".\/some-feature.js\";\r\n<\/code><\/pre>\n<p>The key benefit of <code>import defer<\/code> is that the module is only evaluated on the first use. Consider this example:<\/p>\n<pre class=\"prettyprint language-typescript\" style=\"padding: 10px; border-radius: 10px;\"><code>\/\/ .\/some-feature.ts\r\ninitializationWithSideEffects();\r\n\r\nfunction initializationWithSideEffects() {\r\n  \/\/ ...\r\n  specialConstant = 42;\r\n\r\n  console.log(\"Side effects have occurred!\");\r\n}\r\n\r\nexport let specialConstant: number;\r\n<\/code><\/pre>\n<p>When using <code>import defer<\/code>, the <code>initializationWithSideEffects()<\/code> function will not be called until you actually access a property of the imported namespace:<\/p>\n<pre class=\"prettyprint language-typescript\" style=\"padding: 10px; border-radius: 10px;\"><code>import defer * as feature from \".\/some-feature.js\";\r\n\r\n\/\/ No side effects have occurred yet\r\n\r\n\/\/ ...\r\n\r\n\/\/ As soon as `specialConstant` is accessed, the contents of the `feature`\r\n\/\/ module are run and side effects have taken place.\r\nconsole.log(feature.specialConstant); \/\/ 42\r\n<\/code><\/pre>\n<p>Because evaluation of the module is deferred until you access a member off of the module, you cannot use named imports or default imports with <code>import defer<\/code>:<\/p>\n<pre class=\"prettyprint language-typescript\" style=\"padding: 10px; border-radius: 10px;\"><code>\/\/ \u274c Not allowed\r\nimport defer { doSomething } from \"some-module\";\r\n\r\n\/\/ \u274c Not allowed  \r\nimport defer defaultExport from \"some-module\";\r\n\r\n\/\/ \u2705 Only this syntax is supported\r\nimport defer * as feature from \"some-module\";\r\n<\/code><\/pre>\n<p>Note that when you write <code>import defer<\/code>, the module and its dependencies are fully loaded and ready for execution.\nThat means that the module will need to exist, and will be loaded from the file system or a network resource.\nThe key difference between a regular <code>import<\/code> and <code>import defer<\/code> is that <em>the execution of statements and declarations<\/em> is deferred until you access a property of the imported namespace.<\/p>\n<p>This feature is particularly useful for conditionally loading modules with expensive or platform-specific initialization. It can also improve startup performance by deferring module evaluation for app features until they are actually needed.<\/p>\n<p>Note that <code>import defer<\/code> is not transformed or &#8220;downleveled&#8221; at all by TypeScript.\nIt is intended to be used in runtimes that support the feature natively, or by tools such as bundlers that can apply the appropriate transformation.\nThat means that <code>import defer<\/code> will only work under the <code>--module<\/code> modes <code>preserve<\/code> and <code>esnext<\/code>.<\/p>\n<p>We&#8217;d like to extend our thanks to <a href=\"https:\/\/github.com\/nicolo-ribaudo\">Nicol\u00f2 Ribaudo<\/a> who championed the proposal in TC39 and also provided <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/60757\">the implementation for this feature<\/a>.<\/p>\n<h2 id=\"support-for---module-node20\">Support for <code>--module node20<\/code><\/h2>\n<p>TypeScript provides several <code>node*<\/code> options for the <code>--module<\/code> and <code>--moduleResolution<\/code> settings.\nMost recently, <code>--module nodenext<\/code> has supported the ability to <code>require()<\/code> ECMAScript modules from CommonJS modules, and correctly rejects import assertions (in favor of the standards-bound <a href=\"https:\/\/github.com\/tc39\/proposal-import-attributes\">import attributes<\/a>).<\/p>\n<p>TypeScript 5.9 brings a stable option for these settings called <code>node20<\/code>, intended to model the behavior of Node.js v20.\nThis option is unlikely to have new behaviors in the future, unlike <code>--module nodenext<\/code> or <code>--moduleResolution nodenext<\/code>.\nAlso unlike <code>nodenext<\/code>, specifying <code>--module node20<\/code> will imply <code>--target es2023<\/code> unless otherwise configured.\n<code>--module nodenext<\/code>, on the other hand, implies the floating <code>--target esnext<\/code>.<\/p>\n<p>For more information, <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/61805\">take a look at the implementation here<\/a>.<\/p>\n<h2 id=\"summary-descriptions-in-dom-apis\">Summary Descriptions in DOM APIs<\/h2>\n<p>Previously, many of the DOM APIs in TypeScript only linked to the MDN documentation for the API.\nThese links were useful, but they didn&#8217;t provide a quick summary of what the API does.\nThanks to a few changes from <a href=\"https:\/\/github.com\/Bashamega\">Adam Naji<\/a>, TypeScript now includes summary descriptions for many DOM APIs based on the MDN documentation.\nYou can see more of these changes <a href=\"https:\/\/github.com\/microsoft\/TypeScript-DOM-lib-generator\/pull\/1993\">here<\/a> and <a href=\"https:\/\/github.com\/microsoft\/TypeScript-DOM-lib-generator\/pull\/1940\">here<\/a>.<\/p>\n<h2 id=\"expandable-hovers-preview\">Expandable Hovers (Preview)<\/h2>\n<p><em>Quick Info<\/em> (also called &#8220;editor tooltips&#8221; and &#8220;hovers&#8221;) can be very useful for peeking at variables to see their types, or at type aliases to see what they actually refer to.\nStill, it&#8217;s common for people to want to <em>go deeper<\/em> and get details from whatever&#8217;s displayed within the quick info tooltip.\nFor example, if we hover our mouse over the parameter <code>options<\/code> in the following example:<\/p>\n<pre class=\"prettyprint language-typescript\" style=\"padding: 10px; border-radius: 10px;\"><code>export function drawButton(options: Options): void\r\n<\/code><\/pre>\n<p>We&#8217;re left with <code>(parameter) options: Options<\/code>.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2025\/06\/bare-hover-5.8-01.png\" alt=\"Tooltip for a parameter declared as which just shows .\" \/><\/p>\n<p>Do we really need to jump to the definition of the type <code>Options<\/code> just to see what members this value has?<\/p>\n<p>To help here, TypeScript 5.9 is now previewing a feature called <em>expandable hovers<\/em>, or &#8220;quick info verbosity&#8221;.\nIf you use an editor like VS Code, you&#8217;ll now see a <code>+<\/code> and <code>-<\/code> button on the left of these hover tooltips.\nClicking on the <code>+<\/code> button will expand out types more deeply, while clicking on the <code>-<\/code> will go back to the last view.<\/p>\n<p><video style=\"width: 100%;\" src=\"https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2025\/06\/expandable-quick-info-1.mp4\" autoplay=\"autoplay\" loop=\"loop\" width=\"300\" height=\"150\" aria-label=\"Expanding quick info to see more about the type of &#96;Options&#96;.\"><\/video><\/p>\n<p>This feature is currently in preview, and we are seeking feedback for both TypeScript and our partners on Visual Studio Code.\nFor more details, see <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/59940\">the PR for this feature here<\/a>.<\/p>\n<h2 id=\"configurable-maximum-hover-length\">Configurable Maximum Hover Length<\/h2>\n<p>Occasionally, quick info tooltips can become so long that TypeScript will truncate them to make them more readable.\nThe downside here is that often the most important information will be omitted from the hover tooltip, which can be frustrating.\nTo help with this, TypeScript 5.9&#8217;s language server supports a configurable hover length, which can be configured in VS Code via the <code>js\/ts.hover.maximumLength<\/code> setting.<\/p>\n<p>Additionally, the new default hover length is substantially larger than the previous default.\nThis means that in TypeScript 5.9, you should see more information in your hover tooltips by default.\nFor more details, see <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/61662\">the PR for this feature here<\/a> and <a href=\"https:\/\/github.com\/microsoft\/vscode\/pull\/248181\">the corresponding change to Visual Studio Code here<\/a>.<\/p>\n<h2 id=\"optimizations\">Optimizations<\/h2>\n<h3 id=\"cache-instantiations-on-mappers\">Cache Instantiations on Mappers<\/h3>\n<p>When TypeScript replaces type parameters with specific type arguments, it can end up instantiating many of the same intermediate types over and over again.\nIn complex libraries like Zod and tRPC, this could lead to both performance issues and errors reported around excessive type instantiation depth.\nThanks to <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/61505\">a change<\/a> from <a href=\"https:\/\/github.com\/Andarist\">Mateusz Burzy\u0144ski<\/a>, TypeScript 5.9 is able to cache many intermediate instantiations when work has already begun on a specific type instantiation.\nThis in turn avoids lots of unnecessary work and allocations.<\/p>\n<h3 id=\"avoiding-closure-creation-in-fileordirectoryexistsusingsource\">Avoiding Closure Creation in <code>fileOrDirectoryExistsUsingSource<\/code><\/h3>\n<p>In JavaScript, a function expression will typically allocate a new function object, even if the wrapper function is just passing through arguments to another function with no captured variables.\nIn code paths around file existence checks, <a href=\"https:\/\/github.com\/VincentBailly\">Vincent Bailly<\/a> found examples of these pass-through function calls, even though the underlying functions only took single arguments.\nGiven the number of existence checks that could take place in larger projects, he cited a speed-up of around 11%.\n<a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/61822\/\">See more on this change here<\/a>.<\/p>\n<h2 id=\"whats-next\">What&#8217;s Next?<\/h2>\n<p>As you might have heard, much of our recent focus has been on <a href=\"https:\/\/devblogs.microsoft.com\/typescript\/typescript-native-port\/\">the native port of TypeScript<\/a> which will eventually be available as TypeScript 7.\nYou can actually try out the native port today by checking out <a href=\"https:\/\/devblogs.microsoft.com\/typescript\/announcing-typescript-native-previews\/\">TypeScript native previews<\/a>, which are released nightly.<\/p>\n<p>However, we are still developing TypeScript 5.9 and addressing issues, and encourage you to try it out and give us feedback.\nIf you need a snapshot of TypeScript that&#8217;s newer than the beta, <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/nightly-builds.html\">TypeScript also has nightly releases<\/a>, and you can try out the latest editing experience by installing the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-vscode.vscode-typescript-next\">JavaScript and TypeScript Nightly extension for Visual Studio Code<\/a>.<\/p>\n<p>So we hope you try out the beta or a nightly release today and let us know what you think!<\/p>\n<p>Happy Hacking!<\/p>\n<p>&#8211; Daniel Rosenwasser and the TypeScript Team<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we are excited to announce the availability of TypeScript 5.9 Beta. To get started using the beta, you can get it through npm with the following command: npm install -D typescript@beta Let&#8217;s take a look at what&#8217;s new in TypeScript 5.9! Minimal and Updated tsc &#8211;init Support for import defer Support for &#8211;module node20 [&hellip;]<\/p>\n","protected":false},"author":381,"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-4935","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-typescript"],"acf":[],"blog_post_summary":"<p>Today we are excited to announce the availability of TypeScript 5.9 Beta. To get started using the beta, you can get it through npm with the following command: npm install -D typescript@beta Let&#8217;s take a look at what&#8217;s new in TypeScript 5.9! Minimal and Updated tsc &#8211;init Support for import defer Support for &#8211;module node20 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts\/4935","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\/381"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/comments?post=4935"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts\/4935\/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=4935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/categories?post=4935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/tags?post=4935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}