TypeScript: Difference between revisions
NaibStilgar (talk | contribs) Changed references to strong and weak typing to static and dynamic typing. Objects in TypeScript are still weakly typed because their shape can change at runtime. TypeScript adds static (not strong) typing. |
NaibStilgar (talk | contribs) mNo edit summary |
||
Line 27: | Line 27: | ||
| wikibooks = |
| wikibooks = |
||
}} |
}} |
||
'''TypeScript''' is an [[Open-source software|open source]] programming language developed by [[Microsoft]]. It is a superset of [[JavaScript]], and essentially adds optional static typing and class-based[[Object-oriented programming|object oriented programming]] to the language. [[Anders Hejlsberg]], lead architect of [[C Sharp (programming language)|C#]], has worked on development of TypeScript.<ref>http://www.zdnet.com/microsoft-takes-the-wraps-off-typescript-a-superset-of-javascript-7000004993/</ref><ref>http://blogs.msdn.com/b/somasegar/archive/2012/10/01/typescript-javascript-development-at-application-scale.aspx</ref><ref>http://www.zdnet.com/microsoft-typescript-can-the-father-of-c-save-us-from-the-tyranny-of-javascript-7000005054/</ref><ref>http://www.cio.com/article/717679/Microsoft_Augments_Javascript_for_Large_scale_Development</ref> |
'''TypeScript''' is an [[Open-source software|open source]] programming language developed by [[Microsoft]]. It is a superset of [[JavaScript]], and essentially adds optional static typing and class-based [[Object-oriented programming|object oriented programming]] to the language. [[Anders Hejlsberg]], lead architect of [[C Sharp (programming language)|C#]], has worked on development of TypeScript.<ref>http://www.zdnet.com/microsoft-takes-the-wraps-off-typescript-a-superset-of-javascript-7000004993/</ref><ref>http://blogs.msdn.com/b/somasegar/archive/2012/10/01/typescript-javascript-development-at-application-scale.aspx</ref><ref>http://www.zdnet.com/microsoft-typescript-can-the-father-of-c-save-us-from-the-tyranny-of-javascript-7000005054/</ref><ref>http://www.cio.com/article/717679/Microsoft_Augments_Javascript_for_Large_scale_Development</ref> |
||
TypeScript extends Javascript syntax, so any existing Javascript programs work with Typescript without any changes. Typescript is designed for development of large applications and when compiled it produces Javascript to ensure compatibility.<ref>http://arstechnica.com/information-technology/2012/10/microsoft-typescript-the-javascript-we-need-or-a-solution-looking-for-a-problem/</ref> |
TypeScript extends Javascript syntax, so any existing Javascript programs work with Typescript without any changes. Typescript is designed for development of large applications and when compiled it produces Javascript to ensure compatibility.<ref>http://arstechnica.com/information-technology/2012/10/microsoft-typescript-the-javascript-we-need-or-a-solution-looking-for-a-problem/</ref> |
Revision as of 12:54, 3 October 2012
Designed by | Microsoft |
---|---|
Developer | Microsoft |
First appeared | 2012 |
License | Apache License |
Filename extensions | .ts |
Website | http://www.typescriptlang.org/ |
Influenced by | |
JavaScript |
TypeScript is an open source programming language developed by Microsoft. It is a superset of JavaScript, and essentially adds optional static typing and class-based object oriented programming to the language. Anders Hejlsberg, lead architect of C#, has worked on development of TypeScript.[1][2][3][4]
TypeScript extends Javascript syntax, so any existing Javascript programs work with Typescript without any changes. Typescript is designed for development of large applications and when compiled it produces Javascript to ensure compatibility.[5]
Background
Language features
TypeScript is a language extension that adds features to JavaScript.
- Type annotations and compile-time type checking
- Classes
- Interfaces
- Modules
- Arrow functions (Lambda functions)
Type annotations
TypeScript provides static typing through type annotations to enable type checking at compile-time. This is optional and can be ignored to use the regular dynamic typing of Javascript.
function Add(left: number, right: number): number {
return left + right;
}
The annotations for the primitive types are number
, bool
and string
. Weakly, or dynamically, typed structures are of type Any
.
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, so has been done for Node.js and JQuery.
The TypeScript compiler makes use of type inference to infer types when types are not given. If no type can be inferred because of lack of declarations then it will default to the dynamic Any
type.
ECMAScript 6 support
TypeScript adds support for features proposed for the upcoming ECMAScript 6 standard.
These are the constructs
- Classes (with inheritance)
- Modules
- Arrow functions
Although the standard is not ready, Microsoft has said that it aims to align TypeScript's features with the proposed standard.
Classes
TypeScript supports ECMAScript 6 classes with type annotations as a supported option.
class Person {
private name: string;
private age: number;
constructor(name: string, age: number) {
this.name = name;
this.age = age;
}
toString(): string {
return this.name + " (" + this.age + ")";
}
}
Generics
The language specification states that a future version will support generic programming based on type erasure.
Compatibility with JavaScript
TypeScript is a superset of JavaScript. By default the compiler targets ECMA Script 3 (ES3) but ES5 is also supported as an option. A TypeScript application can consume existing Javascript scripts. Compiled TypeScript scripts can be consumed from JavaScript.
Existing frameworks such as JQuery and Node.js are fully supported. Type declarations for these libraries are provided with the source code.
Supported web browsers and platforms
Any web browser on any platform can run TypeScript as it is just compiled into standard JavaScript. A script can either be precompiled into JavaScript or compiled on the fly by including the JavaScript compiler for TypeScript.
Development tools
Compiler
The TypeScript compiler, or tsc
, is written in TypeScript that can be compiled into regular JavaScript that can be executed in any JavaScript engine in any host, such as 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 is using Node.js as a host.
The current version of the compiler supports ECMAScript 3 by default. An option is allows to target ECMAScript 5 to make use of language features exclusive to that version. The language features implemented that will be part of the ECMAScript 6 standard are available in both modes.
IDE and editor support
Microsoft provides a plug-in for Visual Studio 2012 as well as basic text editor support for Sublime Text, EMACS and Vim [6]
The TypeScript website has an interactive playground that provides a rich coding experience.[7]
Open Source
TypeScript is open source and the source code is available from Codeplex under the Apache 2 License. The project is maintained by Microsoft but anyone can contribute by sending feedback, suggestions and bugfixes via the Codeplex project page.[8]
See also
References
- ^ http://www.zdnet.com/microsoft-takes-the-wraps-off-typescript-a-superset-of-javascript-7000004993/
- ^ http://blogs.msdn.com/b/somasegar/archive/2012/10/01/typescript-javascript-development-at-application-scale.aspx
- ^ http://www.zdnet.com/microsoft-typescript-can-the-father-of-c-save-us-from-the-tyranny-of-javascript-7000005054/
- ^ http://www.cio.com/article/717679/Microsoft_Augments_Javascript_for_Large_scale_Development
- ^ http://arstechnica.com/information-technology/2012/10/microsoft-typescript-the-javascript-we-need-or-a-solution-looking-for-a-problem/
- ^ .http://blogs.msdn.com/b/interoperability/archive/2012/10/01/sublime-text-vi-emacs-typescript-enabled.aspx
- ^ http://www.typescriptlang.org/Playground/
- ^ http://typescript.codeplex.com/