TypeScript
{{Short description|Programming language and superset of JavaScript}}
{{For|the typed instance analogous to a handwritten document|manuscript}}
{{Use dmy dates|date=January 2025}}
{{Infobox programming language
| name = TypeScript
| logo = Typescript.svg
| logo caption =
| screenshot =
| screenshot caption =
| paradigm = Multi-paradigm: functional, generic, imperative, object-oriented
| family = ECMAScript
| designer = Microsoft,
Anders Hejlsberg,
Luke Hoban
| developer = Microsoft
| released = {{Start date and age|2012|10|01|df=yes}}{{cite web |url=https://typescript.codeplex.com/releases/view/95554 |title=TypeScript |work=CodePlex |access-date=26 April 2015 |archive-date=3 April 2015 |archive-url=https://web.archive.org/web/20150403224440/https://typescript.codeplex.com/releases/view/95554 |url-status=dead}}
| latest release version = {{wikidata|property|edit|reference|P548=Q2804309|P348}}
| latest release date={{start date and age|{{wikidata|qualifier|single|P548=Q2804309|P348|P577}}}}
| latest preview version = {{wikidata|property|edit|reference|P548=Q51930650|P348}}
| latest preview date =
| typing = Duck, gradual, structural,{{cite web |title=Type Compatibility |url=https://www.typescriptlang.org/docs/handbook/type-compatibility.html |website=TypeScript |access-date=21 March 2018 |archive-date=12 March 2018 |archive-url=https://web.archive.org/web/20180312103740/http://www.typescriptlang.org/docs/handbook/type-compatibility.html |url-status=live}} strong
| scope = lexical
| programming language =
| platform =
| operating system =
| license = Apache 2.0
| file ext = .ts, .tsx, .mts, .cts
| website = {{URL|https://www.typescriptlang.org/}}
| wikibooks =
| implementations =
| dialects =
| influenced by = C#, F#,{{cite web |title=The Early History of F# |url=https://fsharp.org/history/hopl-final/hopl-fsharp.pdf |quote=TypeScript was directly influenced by F#: one of the originators of TypeScript was Luke Hoban, who began TypeScript (then called Strada) immediately after working on F# 2.0. Recently he noted the influence of F# on early parts of the TypeScript design [Hoban 2017]. |access-date=5 February 2024 |archive-date=9 August 2024 |archive-url=https://web.archive.org/web/20240809075047/https://fsharp.org/history/hopl-final/hopl-fsharp.pdf |url-status=live}} Java, JavaScript, ActionScript{{Cite web |last1=Nelson |first1=Gary |date=28 April 2020 |title=How ActionScript foreshadowed TypeScript |url=https://javascript.plainenglish.io/how-actionscript-foreshadowed-typescript-149cdb764de9 |access-date=9 July 2022 |website=Medium |language=en |archive-date=9 August 2024 |archive-url=https://web.archive.org/web/20240809080212/https://javascript.plainenglish.io/how-actionscript-foreshadowed-typescript-149cdb764de9?gi=8d034fbd408d |url-status=live}}
| influenced = AtScript, AssemblyScript, ArkTS
}}
TypeScript (abbreviated as TS) is a high-level programming language that adds static typing with optional type annotations to JavaScript. It is designed for developing large applications and transpiles to JavaScript.{{cite web |last1=Bright |first1=Peter |date=3 October 2012 |title=Microsoft TypeScript: the JavaScript we need, or a solution looking for a problem? |url=https://arstechnica.com/information-technology/2012/10/microsoft-typescript-the-javascript-we-need-or-a-solution-looking-for-a-problem/ |access-date=26 April 2015 |work=Ars Technica |publisher=Condé Nast |archive-date=9 October 2018 |archive-url=https://web.archive.org/web/20181009164414/https://arstechnica.com/information-technology/2012/10/microsoft-typescript-the-javascript-we-need-or-a-solution-looking-for-a-problem/ |url-status=live}} It is developed by Microsoft as free and open-source software released under an Apache License 2.0.
TypeScript may be used to develop JavaScript applications for both client-side and server-side execution (as with Node.js, Deno or Bun). Multiple options are available for transpiling. The default TypeScript Compiler can be used,{{Cite web|url=https://code.visualstudio.com/docs/languages/typescript|title=TypeScript Programming with Visual Studio Code|website=code.visualstudio.com|language=en|access-date=12 February 2019|archive-date=22 September 2022|archive-url=https://web.archive.org/web/20220922080247/https://code.visualstudio.com/docs/languages/typescript|url-status=live}} or the Babel compiler can be invoked to convert TypeScript to JavaScript.
TypeScript supports definition files that can contain type information of existing JavaScript libraries, much like C++ header files can describe the structure of existing object files. This enables other programs to use the values defined in the files as if they were statically typed TypeScript entities. There are third-party header files for popular libraries such as jQuery, MongoDB, and D3.js. TypeScript headers for the Node.js library modules are also available, allowing development of Node.js programs within TypeScript.{{cite web |url=https://github.com/borisyankov/DefinitelyTyped |title=borisyankov/DefinitelyTyped |work=GitHub |access-date=26 April 2015 |archive-date=1 November 2015 |archive-url=https://web.archive.org/web/20151101104210/https://github.com/borisyankov/DefinitelyTyped |url-status=live}}
The TypeScript compiler is written in TypeScript and compiled to JavaScript. It is licensed under the Apache License 2.0. Anders Hejlsberg, lead architect of C# and creator of Delphi and Turbo Pascal, has worked on developing TypeScript.{{cite web|url=https://www.zdnet.com/article/microsoft-takes-the-wraps-off-typescript-a-superset-of-javascript/|title=Microsoft takes the wraps off TypeScript, a superset of JavaScript|last1=Foley|first1=Mary Jo|date=1 October 2012|work=ZDNet|publisher=CBS Interactive|access-date=26 April 2015|archive-date=13 November 2014|archive-url=https://web.archive.org/web/20141113161248/http://www.zdnet.com/microsoft-takes-the-wraps-off-typescript-a-superset-of-javascript-7000004993/|url-status=live}}{{cite web |last1=Somasegar |first1=S. |date=1 October 2012 |title=TypeScript: JavaScript Development at Application Scale |url=http://blogs.msdn.com/b/somasegar/archive/2012/10/01/typescript-javascript-development-at-application-scale |url-status=deviated |archive-url=https://web.archive.org/web/20170926142536/https://blogs.msdn.microsoft.com/somasegar/2012/10/01/typescript-javascript-development-at-application-scale/ |archive-date=26 September 2017 |access-date=26 April 2015 |website=Somasegar's blog |publisher=Microsoft}}{{cite web|url=https://www.zdnet.com/article/microsoft-typescript-can-the-father-of-c-save-us-from-the-tyranny-of-javascript/|title=Microsoft TypeScript: Can the father of C# save us from the tyranny of JavaScript?|last1=Baxter-Reynolds|first1=Matt|date=1 October 2012|work=ZDNet|access-date=26 April 2015|archive-date=3 August 2014|archive-url=https://web.archive.org/web/20140803030303/http://www.zdnet.com/microsoft-typescript-can-the-father-of-c-save-us-from-the-tyranny-of-javascript-7000005054/|url-status=live}}{{cite web|url=http://www.cio.com/article/717679/Microsoft_Augments_Javascript_for_Large_scale_Development|title=Microsoft Augments Javascript for Large-scale Development|last1=Jackson|first1=Joab|date=1 October 2012|work=CIO|publisher=IDG Enterprise|access-date=26 April 2015|archive-date=17 December 2013|archive-url=https://web.archive.org/web/20131217223751/http://www.cio.com/article/717679/Microsoft_Augments_Javascript_for_Large_scale_Development|url-status=dead}}
History
TypeScript was released to the public in October 2012, with version 0.8, after two years of internal development at Microsoft.{{cite web |url=http://www.infoworld.com/d/application-development/microsoft-augments-javascript-large-scale-development-203737 |title=Microsoft augments JavaScript for large-scale development |date=1 October 2012 |work=InfoWorld |publisher=IDG |access-date=26 April 2015 |archive-date=31 May 2013 |archive-url=https://web.archive.org/web/20130531084330/http://www.infoworld.com/d/application-development/microsoft-augments-javascript-large-scale-development-203737 |url-status=live}}{{cite web |url=https://devblogs.microsoft.com/typescript/announcing-typescript-1-0/ |title=Announcing TypeScript 1.0 |date=2 April 2014 |first1=Jonathan |last1=Turner |publisher=Microsoft |work=TypeScript Language team blog |access-date=20 October 2021 |archive-date=5 September 2015 |archive-url=https://web.archive.org/web/20150905104620/http://blogs.msdn.com/b/typescript/archive/2014/04/02/announcing-typescript-1-0.aspx |url-status=live}} Soon after the initial public release, Miguel de Icaza praised the language, but criticized the lack of mature integrated development environment (IDE) support apart from Microsoft Visual Studio, which was unavailable then on Linux and macOS.{{cite web |url=http://tirania.org/blog/archive/2012/Oct-01.html |title=TypeScript: First Impressions |date=1 October 2012 |last1=de Icaza |first1=Miguel |author-link=Miguel de Icaza |quote=But TypeScript only delivers half of the value in using a strongly typed language to Unix developers: strong typing. Intellisense, code completion and refactoring are tools that are only available to Visual Studio Professional users on Windows. There is no Eclipse, MonoDevelop or Emacs support for any of the language features. |access-date=12 October 2012 |archive-date=24 February 2019 |archive-url=https://web.archive.org/web/20190224173403/https://tirania.org/blog/archive/2012/Oct-01.html |url-status=live}}{{cite web |url=https://www.zdnet.com/article/microsoft-typescript-can-the-father-of-c-save-us-from-the-tyranny-of-javascript/ |title=Microsoft TypeScript: Can the father of C# save us from the tyranny of JavaScript? |date=1 October 2012 |publisher=ZDNet |quote=And I think this is a pretty big misstep. If you're building web apps that run on anything other than Windows, you're likely using a Mac and most likely not using Visual Studio. You need the Visual Studio plug-in to get the IntelliSense. All you get without Visual Studio is the strong-typing. You don't get the productivity benefits you get from IntelliSense. |access-date=12 October 2012 |archive-date=3 August 2014 |archive-url=https://web.archive.org/web/20140803030303/http://www.zdnet.com/microsoft-typescript-can-the-father-of-c-save-us-from-the-tyranny-of-javascript-7000005054/ |url-status=live}} As of April 2021 there is support in other IDEs and text editors, including Emacs, Vim, WebStorm, Atom{{cite web |url=https://github.com/TypeStrong/atom-typescript |title=TypeStrong: The only TypeScript package you will ever need |website = GitHub |access-date=21 July 2016 |archive-date=19 December 2018 |archive-url=https://web.archive.org/web/20181219102240/https://github.com/TypeStrong/atom-typescript |url-status=live}} and Microsoft's own Visual Studio Code.{{cite web |url=http://www.drdobbs.com/windows/working-with-typescript-in-visual-studio/240154792 |title=Working with TypeScript in Visual Studio 2012 |date=14 May 2013 |work=Dr. Dobb's Journal |first1=Gastón |last1=Hillar |access-date=26 April 2015 |archive-date=29 September 2018 |archive-url=https://web.archive.org/web/20180929115630/http://www.drdobbs.com/windows/working-with-typescript-in-visual-studio/240154792 |url-status=live}} TypeScript 0.9, released in 2013, added support for generics.{{cite web |url=https://www.theregister.co.uk/2013/06/18/typescript_update_0_9/ |title=TypeScript 0.9 arrives with new compiler, support for generics |date=18 June 2013 |work=The Register |access-date=26 April 2015 |archive-date=11 March 2018 |archive-url=https://web.archive.org/web/20180311081207/https://www.theregister.co.uk/2013/06/18/typescript_update_0_9/ |url-status=live}}
TypeScript 1.0 was released at Microsoft's Build developer conference in 2014.{{cite web |url=http://channel9.msdn.com/Events/Build/2014/3-576 |title=TypeScript |last1=Hejlsberg |first1=Anders |author1-link=Anders Hejlsberg |date=2 April 2014 |publisher=Microsoft |work=Channel 9 |access-date=26 April 2015 |archive-date=25 May 2015 |archive-url=https://web.archive.org/web/20150525013836/http://channel9.msdn.com/Events/Build/2014/3-576 |url-status=live}} Visual Studio 2013 Update 2 provided built-in support for TypeScript.{{cite web |url=http://www.pcworld.com/article/2101920/microsoft-typescript-graduates-to-visual-studio.html |title=Microsoft TypeScript graduates to Visual Studio |first1=Joab |last1=Jackson |date=25 February 2014 |work=PC World |publisher=IDG |access-date=26 April 2015 |archive-date=11 March 2016 |archive-url=https://web.archive.org/web/20160311175558/http://www.pcworld.com/article/2101920/microsoft-typescript-graduates-to-visual-studio.html |url-status=live}} Further improvement were made in July 2014, when the development team announced a new TypeScript compiler, asserted to have a five-fold performance increase. Simultaneously, the source code, which was initially hosted on CodePlex, was moved to GitHub.{{cite web |url=http://blogs.msdn.com/b/typescript/archive/2014/07/21/new-compiler-and-moving-to-github.aspx |archive-url=https://web.archive.org/web/20140722205833/http://blogs.msdn.com/b/typescript/archive/2014/07/21/new-compiler-and-moving-to-github.aspx |url-status=dead |archive-date=22 July 2014 |title=New Compiler and Moving to GitHub |date=21 July 2014 |publisher=Microsoft |work=TypeScript Language team blog |first1=Jonathan |last1=Turner |access-date=26 April 2015}}
On 22 September 2016, TypeScript 2.0 was released, introducing several features, including the ability for programmers to optionally enforce null safety,{{cite web|first1=Peter|last1=Bright|url=https://arstechnica.com/information-technology/2016/09/typescript-microsofts-javascript-for-big-applications-reaches-version-2-0/|title=TypeScript, Microsoft's JavaScript for big applications, reaches version 2.0|work=Ars Technica|publisher=Condé Nast|date=22 September 2016|access-date=22 September 2016|archive-date=21 December 2018|archive-url=https://web.archive.org/web/20181221125826/https://arstechnica.com/information-technology/2016/09/typescript-microsofts-javascript-for-big-applications-reaches-version-2-0/|url-status=live}} to mitigate what's sometimes referred to as the billion-dollar mistake.
TypeScript 3.0 was released on 30 July 2018,{{Cite web |url=https://devblogs.microsoft.com/typescript/announcing-typescript-3-0/ |title=Announcing TypeScript 3.0 |date=30 July 2018 |access-date=16 March 2020 |archive-date=30 May 2020 |archive-url=https://web.archive.org/web/20200530031718/https://devblogs.microsoft.com/typescript/announcing-typescript-3-0/ |url-status=live}} bringing many language additions like tuples in rest parameters and spread expressions, rest parameters with tuple types, generic rest parameters and so on.{{Cite web |url=https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html |title=TypeScript 3.0 |date=30 July 2018 |access-date=16 March 2020 |archive-date=6 June 2020 |archive-url=https://web.archive.org/web/20200606214433/https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html |url-status=live}}
TypeScript 4.0 was released on 20 August 2020.{{Cite web|date=20 August 2020|title=Announcing TypeScript 4.0|url=https://devblogs.microsoft.com/typescript/announcing-typescript-4-0/|access-date=30 October 2020|website=TypeScript|language=en-US|archive-date=9 August 2024|archive-url=https://web.archive.org/web/20240809080059/https://devblogs.microsoft.com/typescript/announcing-typescript-4-0/|url-status=live}} While 4.0 did not introduce any breaking changes, it added language features such as Custom JSX Factories and Variadic Tuple Types.
TypeScript 5.0 was released on 16 March 2023 and included support for decorators.{{Cite web |title=Documentation – TypeScript 5.0 |url=https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html |access-date=18 May 2023 |website=www.typescriptlang.org |language=en |archive-date=9 August 2024 |archive-url=https://web.archive.org/web/20240809080228/https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html |url-status=live}}
On March 11, 2025 Anders Hejlsberg announced on the TypeScript blog that the team is working on a Go port of the TypeScript compiler to be released as TypeScript version 7.0 later this year. It is expected to feature a 10x speedup.{{Cite web |last1=Hejlsberg |first1=Anders |author1-link=Anders Hejlsberg |date=2025-03-11 |title=A 10x Faster TypeScript |url=https://devblogs.microsoft.com/typescript/typescript-native-port/ |access-date=2025-03-11 |website=TypeScript |language=en-US}}
Design
TypeScript originated from the shortcomings of JavaScript for developing large-scale applications both at Microsoft and among their external customers.{{cite web |url=http://www.hanselminutes.com/340/what-is-typescript-and-why-with-anders-hejlsberg |title=What is TypeScript and why with Anders Hejlsberg |last1=Hejlsberg |first1=Anders |author1-link=Anders Hejlsberg |publisher=www.hanselminutes.com |date=5 October 2012 |access-date=15 January 2014 |archive-date=27 December 2018 |archive-url=https://web.archive.org/web/20181227152425/https://www.hanselminutes.com/340/what-is-typescript-and-why-with-anders-hejlsberg |url-status=live}} Challenges with dealing with complex JavaScript code led to demand for custom tooling to ease developing of components in the language.{{cite web |url=http://blogs.msdn.com/b/somasegar/archive/2012/10/01/typescript-javascript-development-at-application-scale.aspx |title=TypeScript: JavaScript Development at Application Scale |last1=Somasegar |first1=S. |publisher=msdn.com |date=1 October 2012 |url-status=live |archive-url=https://web.archive.org/web/20150422145537/http://blogs.msdn.com/b/somasegar/archive/2012/10/01/typescript-javascript-development-at-applicatio |archive-date=22 April 2015 |access-date=27 November 2013}}
Developers sought a solution that would not break compatibility with the ECMAScript (ES) standard and its ecosystem, so a compiler was developed to transform a superset of JavaScript with type annotations and classes (TypeScript files) back into vanilla ECMAScript 5 code. TypeScript classes were based on the then-proposed ECMAScript 6 class specification to make writing prototypal inheritance less verbose and error-prone, and type annotations enabled IntelliSense and improved tooling.
Features
TypeScript adds the following syntax extensions to JavaScript:
- Type signatures (annotations) and compile-time type checking
- Type inference
- Interfaces
- Enumerated types
- Generics
- Namespaces
- Tuples
- Explicit resource management{{Cite web |title=Documentation – TypeScript 5.2 |url=https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html |access-date=9 November 2023 |website=www.typescriptlang.org |language=en |archive-date=9 August 2024 |archive-url=https://web.archive.org/web/20240809080229/https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html |url-status=live}}
Syntactically, TypeScript is very similar to JScript .NET, another Microsoft implementation of the ECMA-262 language standard that added support for static typing and classical object-oriented language features such as classes, inheritance, interfaces, and namespaces. Other inspirations include Java and C#.
= Type annotations =
TypeScript provides static typing through type annotations to enable type checking at compile time.
function add(left: number, right: number): number {
return left + right;
}
Primitive types are annotated using all-lowercase types, such as number
, boolean
, bigint
, and string
. These types are distinct from their boxed counterparts (Number
, Boolean
, etc), which cannot have operations performed from values directly (a Number
and number
cannot be added). There are additionally undefined
and null
types for their respective values.
All other non-primitive types are annotated using their class name, such as Error
. Arrays can be written in two different ways which are both syntactically the same: the generic-based syntax Array
and a shorthand with T[]
.
Additional built-in data types are tuples, unions, never
and any
:
- An array with predefined data types at each index is a tuple, represented as
[type1, type2, ..., typeN]
. - A variable that can hold more than one type of data is a union, represented using the logical OR
|
symbol (string | number
). - The
never
type is used when a given type should be impossible to create, which is useful for filtering mapped types. - A value of type
any
supports the same operations as a value in JavaScript and minimal static type checking is performed,{{Cite web |title=TypeScript Language Specification p.24 |url=http://www.typescriptlang.org/Content/TypeScript%20Language%20Specification.pdf |url-status=dead |archiveurl=https://web.archive.org/web/20131117065339/http://www.typescriptlang.org/Content/TypeScript%20Language%20Specification.pdf |archivedate=17 November 2013}} which makes it suitable for weakly or dynamically-typed structures. This is generally discouraged practice and should be avoided when possible.{{cite web|title=TypeScript: Documentation – Everyday Types|url=https://www.typescriptlang.org/docs/handbook/2/everyday-types.html|access-date=30 March 2021|website=www.typescriptlang.org/|archive-date=9 August 2024|archive-url=https://web.archive.org/web/20240809080104/https://www.typescriptlang.org/docs/handbook/2/everyday-types.html|url-status=live}}
Type annotations can be exported to a separate declarations file to make type information available for TypeScript scripts using types already compiled into JavaScript. Annotations can be declared for an existing JavaScript library, as has been done for Node.js and jQuery.
The TypeScript compiler makes use of type inference when types are not given. For example, the add
method in the code above would be inferred as returning a number
even if no return type annotation had been provided. This is based on the static types of left
and right
being number
s, and the compiler's knowledge that the result of adding two number
s is always a number
.
If no type can be inferred because of lack of declarations (such as in a JavaScript module without types), then it defaults to the dynamic any
type. Additional module types can be provided using a .d.ts declaration file using the declare module "moduleName"
syntax.
= Declaration files =
When a TypeScript script gets compiled, there is an option to generate a declaration file (with the extension .d.ts
) that functions as an interface to the components in the compiled JavaScript. In the process, the compiler strips away all function and method bodies and preserves only the signatures of the types that are exported. The resulting declaration file can then be used to describe the exported virtual TypeScript types of a JavaScript library or module when a third-party developer consumes it from TypeScript.
The concept of declaration files is analogous to the concept of header files found in C/C++.
declare namespace Arithmetics {
add(left: number, right: number): number;
subtract(left: number, right: number): number;
multiply(left: number, right: number): number;
divide(left: number, right: number): number;
}
Type declaration files can be written by hand for existing JavaScript libraries, as has been done for jQuery and Node.js.
Large collections of declaration files for popular JavaScript libraries are hosted on GitHub in [https://github.com/DefinitelyTyped/DefinitelyTyped DefinitelyTyped].
= Generics =
{{Further|Generic programming}}
TypeScript supports generic programming using a syntax similar to Java.{{cite web |last1=Turner |first1=Jonathan |date=18 June 2013 |title=Announcing TypeScript 0.9 |url=http://blogs.msdn.com/b/typescript/archive/2013/06/18/announcing-typescript-0-9.aspx |work=TypeScript Language team blog |publisher=Microsoft |access-date=18 June 2013 |archive-date=26 November 2013 |archive-url=https://web.archive.org/web/20131126093545/http://blogs.msdn.com/b/typescript/archive/2013/06/18/announcing-typescript-0-9.aspx |url-status=live}} The following is an example of the identity function.{{cite web |title=Generics in Typescript |url=https://www.typescriptlang.org/docs/handbook/generics.html#working-with-generic-type-variables |publisher=Microsoft |access-date=8 April 2020 |archive-date=5 April 2020 |archive-url=https://web.archive.org/web/20200405180639/https://www.typescriptlang.org/docs/handbook/generics.html#working-with-generic-type-variables |url-status=live}}
function id
return x;
}
= Classes =
TypeScript uses the same annotation style for class methods and fields as for functions and variables respectively. Compared with vanilla JavaScript classes, a TypeScript class can also implement an interface through the implements
keyword, use generic parameters similarly to Java, and specify public and private fields.
class Person {
public name: string;
private age: number;
private salary: number;
constructor(name: string, age: number, salary: number) {
this.name = name;
this.age = age;
this.salary = salary;
}
toString(): string {
return `${this.name} (${this.age}) (${this.salary})`;
}
}
= Union types =
{{excerpt|Union type|TypeScript}}
= Enumerated types =
{{excerpt|Enumerated type|TypeScript|subsections=yes}}
= Modules and namespaces =
TypeScript distinguishes between modules and namespaces. Both features in TypeScript support encapsulation of classes, interfaces, functions and variables into containers. Namespaces (formerly internal modules) use JavaScript immediately-invoked function expressions to encapsulate code, whereas modules (formerly external modules) use existing JavaScript library patterns (CommonJS or ES Modules).{{cite web |url=http://blog.oio.de/2014/01/31/an-introduction-to-typescript-module-system/ |title=An introduction to TypeScript's module system |publisher=blog.oio.de |date=31 January 2014 |last1=Sothmann |first1=Sönke |access-date=21 February 2014 |archive-date=1 February 2014 |archive-url=https://web.archive.org/web/20140201102512/http://blog.oio.de/2014/01/31/an-introduction-to-typescript-module-system/ |url-status=dead}}
Compatibility with JavaScript
{{Further|JavaScript}}
As TypeScript is simply a superset of JavaScript, existing JavaScript can be quickly adapted to TypeScript and TypeScript program can seamlessly consume JavaScript. The compiler can target all ECMAScript versions 5 and above, transpiling modern features like classes and arrow functions to their older counterparts.
With TypeScript, it is possible to use existing JavaScript code, incorporate popular JavaScript libraries, and call TypeScript-generated code from other JavaScript.{{cite web |title=Welcome to TypeScript |url=http://www.typescriptlang.org/ |access-date=26 April 2015 |work=typescriptlang.org |publisher=Microsoft |archive-date=10 March 2018 |archive-url=https://web.archive.org/web/20180310153413/https://www.typescriptlang.org/ |url-status=live}} Type declarations for these libraries are usually provided with the source code but can be declared or installed separately if needed.
Development tools
= Compiler =
The TypeScript compiler, named tsc
, is written in TypeScript. As a result, it can be compiled into regular JavaScript and can then be executed in any JavaScript engine (e.g. a browser). The compiler package comes bundled with a script host that can execute the compiler. It is also available as a Node.js package that uses Node.js as a host.
The compiler can target a given edition of ECMAScript (such as ECMAScript 5 for legacy browser compatibility), but by default compiles for the latest standards.
= IDE and editor support =
- Microsoft provides a plug-in for Visual Studio 2012 and WebMatrix, full integrated support in Visual Studio 2013, Visual Studio 2015, and basic text editor support for Emacs and Vim.{{cite web |last1=Bloch |first1=Olivier |title=Sublime Text, Vi, Emacs: TypeScript enabled! |url=http://blogs.msdn.com/b/interoperability/archive/2012/10/01/sublime-text-vi-emacs-typescript-enabled.aspx |publisher=Microsoft |date=1 October 2012 |access-date=28 October 2012 |archive-date=29 October 2012 |archive-url=https://web.archive.org/web/20121029094413/http://blogs.msdn.com/b/interoperability/archive/2012/10/01/sublime-text-vi-emacs-typescript-enabled.aspx |url-status=live}}
- Visual Studio Code supports TypeScript in addition to several other languages, and offers features like debugging and intelligent code completion.
- alm.tools is an open source cloud IDE for TypeScript built using TypeScript, ReactJS and TypeStyle.
- JetBrains supports TypeScript with code completion, refactoring and debugging in its IDEs built on IntelliJ platform, such as PhpStorm 6, WebStorm 6, and IntelliJ IDEA,{{cite web |title=TypeScript support in WebStorm 6 |date=27 February 2013 |url=http://blog.jetbrains.com/webide/2013/02/typescript-support-in-webstorm-6 |publisher=JetBrains |access-date=20 April 2013 |archive-date=2 June 2016 |archive-url=https://web.archive.org/web/20160602072057/http://blog.jetbrains.com/webide/2013/02/typescript-support-in-webstorm-6/ |url-status=live}} as well as their Visual Studio Add-in and extension, ReSharper 8.1.{{cite web |title=TypeScript support in ReSharper 8.1 |date=28 October 2013 |url=http://blog.jetbrains.com/dotnet/2013/10/28/typescript-support-resharper-81/ |publisher=JetBrains |access-date=21 January 2014 |archive-date=2 February 2014 |archive-url=https://web.archive.org/web/20140202124541/http://blog.jetbrains.com/dotnet/2013/10/28/typescript-support-resharper-81/ |url-status=live}}{{Cite web|url=https://www.jetbrains.com/resharper/|title=ReSharper: The Visual Studio Extension for .NET Developers by JetBrains|website=JetBrains}}
- Atom has a TypeScript plugin with support for code completion, navigation, formatting, and fast compilation.{{Cite web|url=https://atom.io/packages/atom-typescript|title=atom-typescript|website=Atom|language=en|access-date=9 January 2020|archive-date=4 October 2016|archive-url=https://web.archive.org/web/20161004165736/https://atom.io/packages/atom-typescript|url-status=live}}
- The online Cloud9 IDE and Codenvy support TypeScript.
- A plugin is available for the NetBeans IDE.
- A plugin is available for the Eclipse IDE (version Kepler)
- TypEcs is available for the Eclipse IDE.
- The Cross Platform Cloud IDE Codeanywhere supports TypeScript.
- Webclipse An Eclipse plugin designed to develop TypeScript and Angular 2.
- Angular IDE A standalone IDE available via npm to develop TypeScript and Angular 2 applications, with integrated terminal support.
- Tide{{snd}} TypeScript Interactive Development Environment for Emacs.
= Integration with build automation tools =
{{Further|Build automation}}
Using plug-ins, TypeScript can be integrated with build automation tools, including Grunt (grunt-ts{{cite web |url=https://github.com/basarat/grunt-ts |title=TypeStrong/grunt-ts |work=GitHub |access-date=26 April 2015 |archive-date=16 April 2020 |archive-url=https://web.archive.org/web/20200416143221/https://github.com/TypeStrong/grunt-ts |url-status=live}}), Apache Maven (TypeScript Maven Plugin{{cite web |url=https://github.com/ppedregal/typescript-maven-plugin |title=ppedregal/typescript-maven-plugin |work=GitHub |access-date=26 April 2015 |archive-date=11 June 2018 |archive-url=https://web.archive.org/web/20180611002148/https://github.com/ppedregal/typescript-maven-plugin |url-status=live}}), Gulp (gulp-typescript{{cite web |url=https://github.com/ivogabe/gulp-typescript |title=ivogabe/gulp-typescript |work=GitHub |access-date=14 July 2017 |archive-date=11 June 2018 |archive-url=https://web.archive.org/web/20180611024633/https://github.com/ivogabe/gulp-typescript |url-status=live}}) and Gradle (TypeScript Gradle Plugin{{cite web |url=https://github.com/sothmann/typescript-gradle-plugin |title=sothmann/typescript-gradle-plugin |work=GitHub |access-date=26 April 2015 |archive-date=11 June 2018 |archive-url=https://web.archive.org/web/20180611010933/https://github.com/sothmann/typescript-gradle-plugin |url-status=live}}).
= Linting tools =
TSLint{{Cite web |url=https://palantir.github.io/tslint/ |title=TSLint |website=palantir.github.io |access-date=11 February 2019 |archive-date=21 December 2022 |archive-url=https://web.archive.org/web/20221221214353/https://palantir.github.io/tslint/ |url-status=live}} scans TypeScript code for conformance to a set of standards and guidelines. ESLint, a standard JavaScript linter, also provided some support for TypeScript via community plugins. However, ESLint's inability to leverage TypeScript's language services precluded certain forms of semantic linting and program-wide analysis.{{Cite web |url=https://medium.com/palantir/tslint-in-2019-1a144c2317a9 |title=TSLint in 2019 |last1=Palantir |date=19 February 2019 |website=Medium |access-date=24 April 2019}} In early 2019, the TSLint team announced the linter's deprecation in favor of typescript-eslint
, a joint effort of the TSLint, ESLint and TypeScript teams to consolidate linting under the ESLint umbrella for improved performance, community unity and developer accessibility.{{Cite web |url=https://www.infoq.com/news/2019/02/tslint-deprecated-eslint |title=TSLint Deprecated to Focus Support on typescript-eslint |website=InfoQ |access-date=24 April 2019 |archive-date=9 August 2024 |archive-url=https://web.archive.org/web/20240809080105/https://www.infoq.com/news/2019/02/tslint-deprecated-eslint/ |url-status=live}}
Release history
{{Version|l|show=111111}}
class="wikitable sortable" |
Version number
! Release date ! Significant changes |
---|
{{Version |o |0.8}}
| {{start date|df=yes|2012|10|01}} | |
{{Version |o |0.9}}
| {{start date|df=yes|2013|06|18}} | |
{{Version |o |1.0}}
| {{start date|df=yes|2014|04|12}} | |
{{Version |o |1.1}}
| {{start date|df=yes|2014|10|06}} | performance improvements |
{{Version |o |1.3}}
| {{start date|df=yes|2014|11|12}} | |
{{Version |o |1.4}}
| {{start date|df=yes|2015|01|20}} | union types, |
{{Version |o |1.5}}
| {{start date|df=yes|2015|07|20}} | ES6 modules, |
{{Version |o |1.6}}
| {{start date|df=yes|2015|09|16}} | JSX support, intersection types, local type declarations, abstract classes and methods, user-defined type guard functions |
{{Version |o |1.7}}
| {{start date|df=yes|2015|11|30}} | |
{{Version |o |1.8}}
| {{start date|df=yes|2016|02|22}} | constraints generics, control flow analysis errors, string literal types, |
{{Version |o |2.0}}
| {{start date|df=yes|2016|09|22}} | null- and undefined-aware types, control flow based type analysis, discriminated union types, |
{{Version |o |2.1}}
| {{start date|df=yes|2016|11|08}} | |
{{Version |o |2.2}}
| {{start date|df=yes|2017|02|22}} | mix-in classes, |
{{Version |o |2.3}}
| {{start date|df=yes|2017|04|27}} | |
{{Version |o |2.4}}
| {{start date|df=yes|2017|06|27}} | dynamic import expressions, string enums, improved inference for generics, strict contravariance for callback parameters |
{{Version |o |2.5}}
| {{start date|df=yes|2017|08|31}} | optional catch clause variables |
{{Version |o |2.6}}
| {{start date|df=yes|2017|10|31}} | strict function types |
{{Version |o |2.7}}
| {{start date|df=yes|2018|01|31}} | constant-named properties, fixed-length tuples |
{{Version |o |2.8}}
| {{start date|df=yes|2018|03|27}} | conditional types, improved |
{{Version |o |2.9}}
| {{start date|df=yes|2018|05|14}} | support for symbols and numeric literals in |
{{Version |o |3.0}}
| {{start date|df=yes|2018|07|30}} | project references, extracting and spreading parameter lists with tuples |
{{Version |o |3.1}}
| {{start date|df=yes|2018|09|27}} | mappable tuple and array types |
{{Version |o |3.2}}
| {{start date|df=yes|2018|11|30}} | stricter checking for |
{{Version |o |3.3}}
| {{start date|df=yes|2019|01|31}} | relaxed rules on methods of union types, incremental builds for composite projects |
{{Version |o |3.4}}
| {{start date|df=yes|2019|03|29}} | faster incremental builds, type inference from generic functions, |
{{Version |o |3.5}}
| {{start date|df=yes|2019|05|29}} | faster incremental builds, omit helper type, improved excess property checks in union types, smarter union type checking |
{{Version |o |3.6}}
| {{start date|df=yes|2019|08|28}} | Stricter generators, more accurate array spread, better Unicode support for identifiers |
{{Version |o |3.7}}
| {{start date|df=yes|2019|11|05}} | Optional chaining, nullish coalescing |
{{Version |o |3.8}}
| {{start date|df=yes|2020|02|20}} | Type-only imports and exports, ECMAScript private fields, top-level |
{{Version |o |3.9}}
| {{start date|df=yes|2020|05|12}} | Improvements in inference, speed improvements |
{{Version |o |4.0}}
| {{start date|df=yes|2020|08|20}} | Variadic tuple types, labeled tuple elements |
{{Version |o |4.1}}
| {{start date|df=yes|2020|11|19}} | Template literal types, key remapping in mapped types, recursive conditional types |
{{Version |o |4.2}}
| {{start date|df=yes|2021|02|25}} | Smarter type alias preservation, leading/middle rest elements in tuple types, stricter checks for the |
{{Version |o |4.3}}
| {{start date|df=yes|2021|05|26}} | Separate write types on properties, |
{{Version |o |4.4}}
| {{start date|df=yes|2021|08|26}} | Control flow analysis of aliased conditions and discriminants, symbol and template string pattern index signatures |
{{Version |o |4.5}}
| {{start date|df=yes|2021|11|17}} | Type and promise improvements, supporting lib from |
{{Version |o |4.6}}
| {{start date|df=yes|2022|02|28}} | Type inference and checks improvements, support for ES2022 target, better ECMAScript handling |
{{Version |o |4.7}}
| {{start date|df=yes|2022|05|24}} | Support for ES modules, instantiation expressions, variance annotations for type parameters, better control-flow checks and type check improvements |
{{Version |o |4.8}}
| {{start date|df=yes|2022|08|25}} | Intersection and union types improvements, better type inference |
{{Version |o |4.9}}
| {{start date|df=yes|2022|11|15}} | |
{{Version |o |5.0}}
| {{start date|df=yes|2023|03|16}} | ES decorators (proposal), type inference improvements, |
{{Version |o |5.1}}
| {{start date|df=yes|2023|06|01}} | Easier implicit returns for |
{{Version |o |5.2}}
| {{start date|df=yes|2023|08|24}} | |
{{Version |o |5.3}}
| {{start date|df=yes|2023|11|20}} | Improved type narrowing, correctness checks and performance optimizations |
{{Version |o |5.4}}
| 6 March 2024 | |
{{Version |o |5.5}}
| 20 June 2024 | Inferred Type Predicates, Regular Expression Syntax Checking, and Type Imports in JSDoc |
{{Version |o |5.6}}
| 9 September 2024 | Advanced type inference, variadic tuple enhancements, partial module declarations. |
{{Version |o |5.7}}
| 22 November 2024 | |
{{Version |c |5.8}}
| 28 February 2025 | |
{{Version |cp |5.9}}
| 2025 | |
{{Version |p |6.0}}
| | Introduce some deprecations and breaking changes to align with the upcoming native codebase. |
{{Version |p |7.0}}
| 2025 | Rewrite in Go with faster performance. |
See also
{{Portal|Free and open-source software}}
References
= Citations =
{{Reflist}}
= Sources =
{{Refbegin}}
- [https://www.genuitec.com/products/webclipse/ "Webclipse: Eclipse Plugin"] {{Webarchive|url=https://web.archive.org/web/20161216150734/https://www.genuitec.com/products/webclipse/ |date=16 December 2016}} Genuitec. Retrieved 9 November 2016.
- [https://www.genuitec.com/products/angular-ide/ "Angular IDE by Webclipse: Standalone IDE"] {{Webarchive|url=https://web.archive.org/web/20161110043934/https://www.genuitec.com/products/angular-ide/ |date=10 November 2016}} Genuitec. Retrieved 9 November 2016.
{{Refend}}
External links
- {{Official website|www.typescriptlang.org}}
- {{GitHub|Microsoft/TypeScript}}
{{JavaScript}}
{{ECMAScript}}
{{Programming languages}}
{{Microsoft APIs}}
{{Microsoft FOSS}}
{{NodeJs}}
{{Authority control}}
Category:Cross-platform software
Category:JavaScript programming language family
Category:Microsoft free software
Category:Microsoft programming languages
Category:Object-based programming languages
Category:Programming languages created in 2012
Category:Programming languages
Category:Software using the Apache license
Category:Source-to-source compilers