Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Aphorismen
Applications
Business Economics & Admin.
My Computers
Cooking
Devices
Folders
Food
Hardware
Infos
Software Development
Sports
Operation Instructions
Todos
Test
Help
Glossary
Community portal
adaptions
Sidebar anpassen
Wiki RB4
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
TypeScript
Page
Discussion
English
Read
Edit
View history
Toolbox
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Concept== TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. TypeScript wird während des Entwicklungsvorgangs mit Hilfe eines '''Transpilers''' (eine Sonderform eines Compilers) in JavaScript übersetzt. The concepts and features below are add-ons to the JavaScript language. The main benefits are: * TypeScript provides the static type system which provides great help in catching programming errors at compile time. * Typescript brings Types, Classes, interfaces & modules. it makes the code more maintainable and scalable. * Typescript comes with several language features. It supports Encapsulation through classes and modules. Supports constructors, properties & functions. It has support for Interfaces. You can make use of Arrow functions or lambdas or anonymous functions. ==Language== ===Statements=== Statements end with a ''';''' but if it is a single line statement it might be ommitted. ===Data Types=== JavaScript has eight data types. The primitive types are * number * string * boolean * bigint * symbol * undefined, and * null. Everything else is an object. The TypeScript Type System supports all of them and also brings its own special types. They are '''unknown''', '''any''', '''void''' & '''never'''. ====Type Annotations==== funcXYZ : <RETURN_TYPE> { } varXYZ : <TYPE> = ...; ====Union types==== The union types are special. They allow a variable to be of either of two types: var x: string | number; ===Variable Declaration=== * let variables are available in block, var variables are available in the function * see also [https://www.typescriptlang.org/docs/handbook/variable-declarations.html here] * [[File:TypeScriptVariableDeclaration1.png|400px]] * <code?</code> after the variable name is short of <code><TYPE>|undefined</code> ===Classes=== * TypeScript offers special syntax for turning a constructor parameter into a class property with the same name and value. If [[TypeScript#Access_Modifier|access modifiers]] there is no need to declare properties export class Menu { constructor( public id: number, public parent_id: number, public name: string, public comment: string ) { ===Interfaces=== Typescript uses in interface in multiple ways (s. [https://www.typescriptlang.org/docs/handbook/interfaces.html here]): * no access modifiers, everything is public interface <INTERFACE_NAME> { ... implements <INTERFACE_NAME> ... ===Access Modifier=== * private * protected * public ===Generics=== ===Functions=== ====Function Parameters==== function doSomething(value: any, options?: <TYPE>) // options parameter is optional ===Decorators=== A Decorator is a special kind of declaration that can be attached to a class declaration, method, accessor, property, or parameter. Decorators use the form <code>@<Expression></code>, where <Expression> must evaluate to a function that will be called at runtime with information about the decorated declaration. ===Non-null assertion/Bang operator=== When you add an exclamation mark after variable/property name, you're telling to TypeScript that you're certain that value is not null or undefined, which prevents the ts2564 compilation error. ===Optional Chaining Operator=== The <code>?.</code> operator always produces the value undefined when it stops descending into a property chain, even when it encounters the value null. ===Import/Export=== Starting with ECMAScript 2015, JavaScript has a concept of [[JScript#Modules|modules]]. TypeScript shares this concept. Each ts-file is javascript module. import { ZipCodeValidator } from "./ZipCodeValidator"; // import a single export from a module ==Installation== C:\Uwes\Programme\nodejs>npm install -g typescript ==Resources== * https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html * [https://www.tektutorialshub.com/typescript-tutorial/ Typescript Tutorial] * [https://www.typescriptlang.org/play?#code/G4QwTgBAtgpgznEBzGAuOAXMBLAdkiAXggCIAJGAG0oHsIB1GsSgExIgCgBjG3OGyjAB0tJAApYCZDACUHDkA Typescript Playground]
Summary:
Please note that all contributions to Wiki RB4 may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Uwe Heuer Wiki New:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width