TypeScript

from Wikipedia, the free encyclopedia
TypeScript
TypeScript Logo.svg
Basic data
Paradigms : functional , imperative , object-oriented ( prototypes , classes ), structured , scripting
Publishing year: 2012
Designer: Microsoft
Developer: Anders Hejlsberg , Microsoft
Current  version 3.9 RC   (April 28, 2020)
Typing : strong , weak , duck , dynamic , static , explicit , implicit
Influenced by: JavaScript , Java , C #
License : Apache license
www.typescriptlang.org

TypeScript is a programming language developed by Microsoft that is based on the proposals for the ECMAScript -6 standard. TypeScript language constructs such as classes , inheritance , modules and anonymous functions have also been adopted in ECMAScript 6.

The TypeScript compiler developed by Microsoft compiles TypeScript code according to ECMA Script 3 (ES3) , optionally also according to ECMA Script 5 (ES5) to plain JavaScript . Every JavaScript code is therefore also valid TypeScript code, so that common JavaScript libraries (such as jQuery or AngularJS ) can also be used in TypeScript.

With modules, TypeScript supports the encapsulation of classes, interfaces, functions and variables in their own namespaces. A distinction is made between internal and external modules. Internal modules are based on the module specification from ECMAScript 6, whereas external modules use a JavaScript library ( AMD or CommonJS ).

TypeScript can be integrated into various build management tools using plug-ins , including Grunt (grunt-ts), Apache Maven (TypeScript Maven plugin), and Gradle (TypeScript Gradle plugin).

history

The first publicly available version of TypeScript was released in 2012 after two years of development by Microsoft in version 0.8. Shortly after the language was announced, it was praised by Miguel de Icaza . However, he complained that there were no other development environments apart from Microsoft Visual Studio , which was not available for Linux and macOS in 2013 . Since 2013 there has been plugin support for Eclipse , which was provided by Palantir Technologies . A large number of text editors and development environments now support TypeScript. These include Emacs , vim , Sublime Text , WebStorm , Atom and Microsoft's own editor Visual Studio Code .

TypeScript 0.9 was released in 2013 and brought support for generic types .

TypeScript 1.0 was presented in 2014 at Microsoft's own developer conference Build. Visual Studio also received support for TypeScript.

In July 2014, the TypeScript developers announced a new compiler that should be five times faster than the old one. At the same time, the previous TypeScript source code was migrated from CodePlex to GitHub .

Version 2.0 was released on September 22nd, 2016, which introduced various new functions. Among other things, an optional function was introduced to prevent variables from being nullinitialized by default . This should lead to fewer null pointer exceptions .

Version 3.0 was released on July 30, 2018. Particularly noteworthy is the new primitive type unknown. Together with void(the unit type) and never(the empty type) it completes the borders of the type hierarchy: unknownis a universal type; any object can be assigned to one of these variables and accordingly unknownnothing can be expected of a value. TypeScript then requests assertions or checks. In contrast to this, it anyis also a universal type, but TypeScript allows the values ​​to be used directly, although there is actually no information about them. This is unknownnothing more than the type-safe equivalent of any.

Functions

TypeScript is an extension that adds the functionality of ECMAScript 6. The following functions are available:

The following functions were added by a backport of ECMAScript 2015:

  • Classes
  • Modules
  • Arrow syntax for anonymous functions
  • Optional parameters and standard parameters

Compatibility with JavaScript

TypeScript is a strict superset of ECMAScript 2015, which is itself a superset of ECMAScript 5, which is often put in reference with JavaScript. A JavaScript program is therefore also a valid TypeScript program. This means that TypeScript can use JavaScript without any problems. The compiler normally uses ECMAScript 5, but it is also possible to use constructs from ECMAScript 3 or 2015.

TypeScript offers the possibility to use existing JavaScript code and known JavaScript libraries.

Method signature

TypeScript offers method signatures that allow methods to be verified during compilation. This is optional and can be ignored.

function add(left: number, right: number): number {
	return left + right;
}

The annotations for the primitive types are Number, Booleanand String.

Classes

TypeScript supports ECMAScript 2015 classes which can use optional method signatures:

class Person {
    private 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})`; // As of version 1.4
    }
}

Generic programming

TypeScript supports generic programming . This is an example of an identity function:

function doSomething<T>(arg: T): T {
    return arg;
}

design

TypeScript is derived from the scripting language JavaScript and aims to remedy its shortcomings in the development of large applications, which Microsoft itself initiated. The challenge of dealing with the complex code of JavaScript led to the creation of a customized tool to simplify the development of these components.

The developers of TypeScript were looking for a solution that would not compromise the compatibility with the standard or the platform independence of JavaScript. With the knowledge that ECMAScript wanted to support class-based programming in the future, TypeScript was developed on this principle. That resulted in a JavaScript compiler with some extensions that translate the code into JavaScript.

ECMAScript 2015 support

TypeScript added support for the ECMAScript 2015 standard.

history

Version number Release date Changes
0.8 October 1, 2012 First publication
0.9 June 18, 2013
1.1 October 6, 2014 Performance improvements
1.3 November 12, 2014 protected Access modifier , tuple types
1.4 20th January 2015 Union types, letand constdeclarations, template strings, type guards, type aliases
1.5 20th July 2015 ES6 modules, namespaceKeyword, for..ofSupport, Decorator
1.6 16th September 2015 JSX support, intersection types, local type declarations, abstract classes and methods, user-defined guard functions
1.7 November 30, 2015 Support for asyncandawait
1.8 February 22, 2016 Constraints generics, control flow error analysis, string literal types, allowJs
2.0 22nd September 2016 nulland undefinedpreventive types, control flow-based nevertype analysis, discriminated union types, type, readonlykeyword,this
2.1 November 8, 2016 keyof and lookup types, mapped types, residual and spread properties for objects
2.2 22nd February 2017 Mix-in classes, objecttype
2.3 April 27, 2017 async Iteration, generic default parameters, strict option
2.3 June 27, 2017 dynamic importexpressions, string enums, improved inheritance for generic data types, strict contravariance for callback parameters
2.5 August 31, 2017 optional catch clause variables for exceptions
2.6 October 31, 2017 strict function types
2.7 January 31, 2018 const-named properties, fixed-length tuples
2.8 March 27, 2018 Conditional types, improvement of keyofin combination with intersection types
2.9 May 31, 2018 Support of numberand symbolnamed properties with keyofand finite maps. import(...)-Types.
3.0 July 30, 2018 Tuples as residual parameters, spread expressions for tuples, generic residual parameters. Optional elements in tuples. The type unknown-Type as a universal type (see also type theory # Special types ). Support for defaultPropsin JSX.
3.1 September 27, 2018 Mapped tuples and array types
3.2 November 30, 2018 Tighter control of bind, callandapply
3.3 January 31, 2019 Loose rules for methods of connection types, incremental builds for joint projects
3.4 29th March 2019 Improvements to incremental builds, composite projects, inference, read-only arrays, type checking for global variables and various others
3.5 29 May 2019
3.6 August 28, 2019
3.7 5th November 2019 Optional chaining, nullish coalescing operator, assertion functions, improved support for methods that neverreturn and many more.
3.8 February 20, 2020 Type-only imports and exports, private fields, top-level awaitand many more changes.
3.9 May 12, 2020 Build speed @‌ts-expect-errorimprovements , commentary, editor improvements, and other changes.

Web links

  • DefinitelyTyped : Collection of TypeScript interfaces for popular JavaScript frameworks

Individual evidence

  1. github.com . (accessed on July 15, 2020).
  2. ECMAScript Wiki. (No longer available online.) Archived from the original on May 22, 2008 ; accessed on April 3, 2013 . Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice.  @1@ 2Template: Webachiv / IABot / wiki.ecmascript.org
  3. a b TypeScript. Retrieved April 3, 2013 (English, TypeScript homepage).
  4. An introduction to TypeScript's module system. Retrieved on February 4, 2014 (English, article on the TypeScript module system).
  5. grunt-ts. Retrieved February 21, 2014 .
  6. TypeScript Maven plugin. Retrieved February 21, 2014 .
  7. TypeScript Gradle Plugin. Retrieved February 21, 2014 .
  8. IDG News Service staff: Microsoft augments JavaScript for large-scale development . In: InfoWorld . ( infoworld.com [accessed July 11, 2018]).
  9. Announcing TypeScript 1.0 . ( microsoft.com [accessed July 11, 2018]).
  10. @ COPYRIGHT @: TypeScript: First Impressions - Miguel de Icaza. Accessed July 11, 2018 .
  11. ^ Matt Baxter-Reynolds: Microsoft TypeScript: Can the father of C # save us from the tyranny of JavaScript? | ZDNet . In: ZDNet . ( zdnet.com [accessed July 11, 2018]).
  12. Julia Schmidt: TypeScript support for Eclipse. Retrieved on July 11, 2018 (German).
  13. TypeScript . In: Eclipse Plugins, Bundles and Products - Eclipse Marketplace . ( eclipse.org [accessed July 11, 2018]).
  14. Type Strong / atom-typescript. Accessed July 11, 2018 .
  15. TypeScript. Retrieved July 11, 2018 .
  16. Working with TypeScript in Visual Studio 2012 . In: Dr. Dobb's . ( drdobbs.com [accessed July 11, 2018]).
  17. ^ New Compiler and Moving to GitHub . ( msdn.com [accessed July 11, 2018]).
  18. TypeScript, Microsoft's JavaScript for big applications, reaches version 2.0 . In: Ars Technica . ( arstechnica.com [accessed July 11, 2018]).
  19. Microsoft Previews New JavaScript-Like Programming Language TypeScript. In: TechCrunch. Retrieved May 18, 2020 (American English).
  20. ^ Angular. Retrieved May 18, 2020 .
  21. Typed JavaScript at Any Scale. Retrieved May 18, 2020 .
  22. Announcing TypeScript 0.9. June 18, 2013, Retrieved May 18, 2020 (American English).
  23. Handbook - Generics. Retrieved May 18, 2020 .
  24. ^ Scott Hanselman: What is TypeScript and why with Anders Hejlsberg. Retrieved May 18, 2020 .
  25. kexugit: TypeScript: JavaScript Development at Application Scale. Retrieved May 18, 2020 (American English).
  26. https://www.typescriptlang.org/docs/handbook/release-notes/typescript-1-7.html accessed on August 1, 2019
  27. Announcing TypeScript 3.7. November 5, 2019, accessed March 2, 2020 (American English).
  28. Announcing TypeScript 3.8. February 20, 2020, accessed March 2, 2020 (American English).
  29. Announcing TypeScript 3.9. May 12, 2020, Retrieved May 14, 2020 (American English).