TypeScript 6.0 की घोषणा
(devblogs.microsoft.com)- JavaScript-आधारित मौजूदा codebase की अंतिम release, और Go में लिखे गए native port TypeScript 7.0 में ट्रांज़िशन की तैयारी करने वाली bridge release
thisका उपयोग न करने वाले functions की context sensitivity में ढील,#/से शुरू होने वाले subpath imports का समर्थन आदि सहित type inference और module resolution में सुधारstrictका defaulttrue,targetका defaultes2025,typesका default[]आदि के साथ compiler option defaults का बड़ा आधुनिकीकरण- ES5 target, AMD/UMD/SystemJS modules,
--baseUrl,--moduleResolution node10आदि जैसे legacy options का बड़े पैमाने पर deprecation - Temporal API, Map के
getOrInsert/getOrInsertComputed,RegExp.escapeआदि जैसे नवीनतम ECMAScript Stage 4 proposals के लिए type support जोड़ा गया
TypeScript 6.0 की स्थिति
- मौजूदा JavaScript codebase पर आधारित अंतिम release, जो TypeScript 7.0 (Go native port) की ओर संक्रमण के लिए bridge की भूमिका निभाती है
- TypeScript 7.0 native code और shared-memory multithreading का उपयोग करता है, और पहले से ही लगभग पूर्णता के करीब है
- 6.0 के अधिकांश बदलाव 7.0 को अपनाने के लिए alignment और तैयारी पर केंद्रित हैं
- TypeScript 7.0 को VS Code extension या npm package के ज़रिए पहले से आज़माया जा सकता है
Beta और RC के बाद के बदलाव
- generic calls (खासकर generic JSX expressions) में function expressions की type checking में समायोजन — इससे मौजूदा code में अधिक bugs पकड़े जा सकते हैं, लेकिन कुछ generic calls में explicit type arguments की ज़रूरत पड़ सकती है
import()calls में भी import assertion syntax (assert) के deprecation का विस्तार लागू- DOM types update — नवीनतम web standards को दर्शाता है, जिसमें Temporal API से जुड़े समायोजन शामिल हैं
this का उपयोग न करने वाले functions की context sensitivity में ढील
- TypeScript, type inference के दौरान बिना explicit type वाले parameters रखने वाले functions को contextually sensitive function के रूप में वर्गीकृत करता है, और उन्हें inference क्रम में बाद में प्रोसेस करता है
- method syntax में लिखे गए functions में implicit
thisparameter होता है, इसलिए उन्हें arrow functions के विपरीत हमेशा context sensitive माना जाता था- इससे object literal के अंदर methods के क्रम के आधार पर type inference fail होने की स्थिति बनती थी
- TypeScript 6.0 में वे functions जिनमें
thisवास्तव में उपयोग नहीं होता अब context sensitive नहीं माने जाते- ऐसे functions को type inference में उच्च प्राथमिकता मिलती है, जिससे method order की परवाह किए बिना सही inference होता है
- Mateusz Burzyński के contribution से लागू
#/ से शुरू होने वाले Subpath Imports का समर्थन
- Node.js की subpath imports सुविधा package के भीतर modules के aliases को
package.jsonकेimportsfield में define करती है - पहले
#के बाद अनिवार्य रूप से कोई character होना चाहिए था, इसलिए#/से शुरू होने वाले paths का उपयोग संभव नहीं था- इससे bundler में
@/prefix convention के अभ्यस्त developers के लिए भ्रम पैदा होता था
- इससे bundler में
- Node.js ने हाल ही में
#/से शुरू होने वाले subpath imports को support करना शुरू किया"#/*": "./dist/*"जैसे concise mappings संभव
- TypeScript 6.0 इसे
--moduleResolution nodenextऔरbundleroptions में support करता है - magic-akari के contribution से लागू
--moduleResolution bundler और --module commonjs का संयोजन अनुमत
- पहले
--moduleResolution bundlerकेवल--module esnextया--module preserveके साथ ही इस्तेमाल किया जा सकता था --moduleResolution node(node10) के deprecation के कारण, यह नया combination कई projects के लिए सबसे उपयुक्त upgrade path है- लंबी अवधि में
--module preserve+--moduleResolution bundlerया--module nodenextकी ओर migration की सिफारिश
--stableTypeOrdering flag
- TypeScript के भीतर types को दिए जाने वाले type IDs processing order के आधार पर तय होते हैं, और union types की sorting इसी पर आधारित होती है
- declaration order के अनुसार declaration emit results बदलने जैसी अप्रत्याशित स्थिति बन सकती है
- TypeScript 7.0 parallel type checking लाता है, इसलिए non-deterministic ID assignment की समस्या हल करने के लिए content-based deterministic sorting algorithm का उपयोग करता है
- उदाहरण:
100 | 500हमेशा एक ही क्रम में output होगा
- उदाहरण:
- 6.0 में
--stableTypeOrderingflag सक्षम करने पर इसे 7.0 के type ordering behavior से match कराया जा सकता है, जिससे दोनों codebases के बीच का अंतर कम होगा- type checking में अधिकतम 25% performance drop हो सकता है
- inference differences से type errors आएँ तो explicit type arguments या variable annotations जोड़कर समाधान किया जा सकता है
- यह flag केवल 6.0 से 7.0 migration diagnosis के लिए है, लंबे समय तक उपयोग की सिफारिश नहीं
es2025 option (target और lib)
- ES2025 में नए JavaScript language features नहीं हैं, लेकिन built-in API types (जैसे
RegExp.escape) जोड़े गए हैं esnextमें मौजूदPromise.try,Iteratormethods,Setmethods आदिes2025में शिफ्ट किए गए- Kenta Moriuchi के contribution से लागू
Temporal API type support
- Stage 4 तक पहुँच चुके Temporal proposal के built-in types को TypeScript 6.0 में शामिल किया गया
--target esnextया"lib": ["esnext"](या granularesnext.temporal) के साथ इस्तेमाल किया जा सकता हैTemporal.Now.instant().subtract(),.add()जैसी APIs को type-safe तरीके से इस्तेमाल किया जा सकता है- यह कई runtimes में पहले से उपलब्ध है और Stage 4 के साथ आधिकारिक JavaScript language का हिस्सा बन चुका है
- Renegade334 के contribution से लागू
Map के "upsert" methods के लिए type support (getOrInsert / getOrInsertComputed)
- Map में key की मौजूदगी जाँचने और न होने पर default value सेट करने वाले दोहराए जाने वाले pattern को सरल बनाता है
- ECMAScript का "upsert" proposal Stage 4 तक पहुँच चुका है, और
MapतथाWeakMapमें दो नए methods जोड़ता हैgetOrInsert: key न होने पर दी गई default value insert करके return करता हैgetOrInsertComputed: जब default value बनाना महँगा हो, तब callback के ज़रिए lazy calculation करता है- callback key को argument के रूप में लेता है, इसलिए key-आधारित default value generation में भी उपयोगी है
esnextlib में जोड़ा गया है और TypeScript 6.0 में तुरंत इस्तेमाल किया जा सकता है- Renegade334 के contribution से लागू
RegExp.escape
- regular expressions के भीतर special characters को escape करने वाला
RegExp.escapefunction Stage 4 तक पहुँच चुका है es2025lib में शामिल है और TypeScript 6.0 में उपलब्ध है- Kenta Moriuchi के contribution से लागू
dom lib में dom.iterable और dom.asynciterable का एकीकरण
- पहले
NodeList,HTMLCollectionआदि पर iteration इस्तेमाल करने के लिए"lib": ["dom", "dom.iterable"]को explicit रूप से लिखना पड़ता था - TypeScript 6.0 में
lib.dom.iterable.d.tsऔरlib.dom.asynciterable.d.tsकी सामग्री पूरी तरहlib.dom.d.tsमें merge कर दी गई हैdom.iterable,dom.asynciterableअब भी refer किए जा सकते हैं, लेकिन वे empty files हैं
- चूँकि सभी प्रमुख आधुनिक browsers इस सुविधा का समर्थन करते हैं, यह आम भ्रम को हटाने वाला convenience improvement है
प्रमुख default changes
strictdefaulttrue: अधिकांश नए projects strict mode चाहते हैं, इसलिए जो projects पहले केfalsebehavior पर निर्भर थे उन्हें explicit"strict": falseसेट करना होगाmoduledefaultesnext: यह दर्शाता है कि ESM अब प्रमुख module format बन चुका हैtargetdefault नवीनतम ES version (वर्तमान मेंes2025): evergreen runtimes के सामान्य होने से पुराने versions के लिए transpile करना अब कम ज़रूरी हैnoUncheckedSideEffectImportsdefaulttrue: side-effect-only imports में typos पकड़ने में मददlibReplacementdefaultfalse: अनावश्यक module resolution failures और watched targets बढ़ने से बचाकर default performance बेहतर करता है
rootDir default बदलकर .
- पहले अगर यह specify न हो तो सभी non-declaration input files की common directory infer करके तय की जाती थी
- इससे यह तय करने के लिए कि कोई file project की है या नहीं, उस project को load और parse करना पड़ता था
- TypeScript 6.0 में default अब वह directory है जहाँ
tsconfig.jsonमौजूद है - अगर source files
tsconfig.jsonसे और गहराई में हों, तो"rootDir": "./src"जैसी explicit setting देनी होगी- अन्यथा
./dist/src/index.jsजैसी अनचाही output structure बन सकती है
- अन्यथा
types default बदलकर []
- पहले
node_modules/@typesके भीतर सभी packages अपने आप शामिल हो जाते थे, जिससे build time में बड़ा overhead आता था- सामान्य repositories में सैकड़ों
@typespackages transitively शामिल हो जाते थे
- सामान्य repositories में सैकड़ों
- TypeScript 6.0 में default
[](empty array) कर दिया गया, ताकि अनावश्यक declaration files load न हों - वास्तविक build time में 20~50% सुधार के उदाहरण देखे गए
- अधिकांश projects में
"types": ["node"]या"types": ["node", "jest"]जैसी explicit settings की ज़रूरत होगी"types": ["*"]से पुराना behavior बहाल किया जा सकता है
Deprecation items
target: es5 deprecation
- ES5 target का उपयोग लगभग समाप्त हो चुका है क्योंकि IE रिटायर हो चुका है और evergreen browsers आम हो गए हैं
- minimum target अब ES2015 है; अगर ES5 output चाहिए तो external compiler के उपयोग की सिफारिश
--downlevelIteration deprecation
- इसका प्रभाव केवल ES5 emit में था, इसलिए ES5 target deprecation के साथ इसका उद्देश्य भी समाप्त
--moduleResolution node(node10) deprecation
- यह Node.js 10 के module resolution algorithm को दर्शाता था, जो आधुनिक Node.js behavior से मेल नहीं खाता
nodenext(सीधे Node.js target करने के लिए) याbundler(bundlers/Bun के लिए) में migration की सिफारिश
AMD, UMD, SystemJS module values deprecation
--module amd,--module umd,--module systemjs,--module noneअब supported नहीं हैं- चूँकि ESM browsers और Node.js दोनों में व्यापक रूप से supported है, bundler या ESM target की ओर जाना आवश्यक है
--baseUrl deprecation
- इसे मुख्यतः
pathsके prefix के रूप में इस्तेमाल किया जाता था, लेकिन यह module resolution के lookup root की तरह भी काम करता था, जिससे अनचाहे path resolution issues पैदा होते थे baseUrlहटाकरpathsentries में सीधे prefix जोड़कर migration किया जा सकता है- उदाहरण:
"@app/*": ["app/*"]→"@app/*": ["./src/app/*"]
- उदाहरण:
--moduleResolution classic deprecation
- यह TypeScript का मूल module resolution algorithm था, लेकिन अब लगभग सभी व्यावहारिक मामलों में
nodenextयाbundlerइसे replace कर सकते हैं
esModuleInterop false और allowSyntheticDefaultImports false deprecation
- इन दोनों options को
falseपर सेट करना अब संभव नहीं होगा, यानी safe interop behavior हमेशा enabled रहेगा import * as express from "express"→import express from "express"जैसी adjustment की ज़रूरत पड़ सकती है
--alwaysStrict false deprecation
- अब सभी code को JavaScript strict mode में माना जाएगा, इसलिए
await,static,privateआदि को सामान्य identifiers की तरह इस्तेमाल करने वाले code में नाम बदलने होंगे
outFile deprecation
- यह कई input files को एक में combine करने की सुविधा थी, लेकिन अब Webpack, Rollup, esbuild, Vite जैसे external bundlers इसका स्थान ले चुके हैं
- यह निर्णय TypeScript की मूल भूमिका, यानी type checking और declaration emit, पर फोकस बनाए रखने के लिए लिया गया है
legacy module syntax (namespace declarations) deprecation
module Foo { ... }syntax hard deprecated है; अबnamespace Foo { ... }का उपयोग करना होगाdeclare module "some-module" { ... }जैसे ambient module declarations अब भी supported हैं- उद्देश्य ECMAScript के
moduleblock proposal के साथ टकराव से बचना है
Import asserts keyword deprecation
import ... asserts { type: "json" }→import ... with { type: "json" }में बदलाव करना होगा- यह import assertions proposal के import attributes proposal (
withkeyword) में बदलने के कारण किया गया है
no-default-lib directive deprecation
/// <reference no-default-lib="true"/>अब supported नहीं है;--noLibया--libReplacementके उपयोग की सिफारिश
tsconfig.json मौजूद होने पर command-line file specification error
tsc foo.tsचलाने पर यदि उसी directory मेंtsconfig.jsonहो, तो error होगी- इसे explicit रूप से ignore करने के लिए
--ignoreConfigflag उपलब्ध है
TypeScript 7.0 की तैयारी
- 6.0 में deprecated options को
"ignoreDeprecations": "6.0"setting के साथ बिना error जारी रखा जा सकता है, लेकिन 7.0 में वे पूरी तरह हटा दिए जाएँगे - ts5to6 tool के ज़रिए
baseUrl,rootDirआदि का auto-adjustment संभव है - TypeScript 7.0 के कुछ महीनों में release होने की उम्मीद है, और Microsoft के भीतर तथा बाहर के बड़े codebases में इसे पहले से व्यापक रूप से अपनाया जा रहा है
- native preview nightly build और VS Code extension के ज़रिए feedback देने की सिफारिश
3 टिप्पणियां
Go-आधारित compiler पर पूरी तरह स्विच होने का समय आने का इंतज़ार है!
अरे? क्या TypeScript बाद में Go-आधारित native में बदल जाएगा?
सिर्फ compiler