Thursday, April 5, 2018

TypeScript



TypeScript is an open-source programming language developed and maintained by Microsoft. 


Every JavaScript program is also a TypeScript program. It is a strict syntactical superset of JavaScript with design-time support for type safety and tooling. TypeScript adds optional types, classes, and modules to JavaScript.

TypeScript is designed for development of large applications and transpile to JavaScript

TypeScript is a primary language for Angular application development. 

Browsers can't execute TypeScript directly. Typescript must be "transpiled" into JavaScript using the tsc compiler, which requires some configuration. The TypeScript compiler is itself written in TypeScript and compiled to JavaScript.

The TypeScript compiler performs only file local transformations on TypeScript programs and does not re-order variables declared in TypeScript. This leads to JavaScript output that closely matches the TypeScript input. TypeScript does not transform variable names, making tractable the direct debugging of emitted JavaScript. TypeScript optionally provides source maps, enabling source-level debugging. TypeScript tools typically emit JavaScript upon file save, preserving the test, edit, refresh cycle commonly used in JavaScript development.

TypeScript compiles to clean, simple JavaScript code which runs on any browser, in Node.js, or in any JavaScript engine that supports ECMAScript 3 (or newer).

The typescript was first made public in October 2012 (at version 0.8).On 22 September 2016, TypeScript 2.0 was released; it introduced several features, including the ability for programmers to optionally prevent variables from being assigned null values.

Installing
For the latest stable version: 
npm install -g  typescript

Building your first TypeScript file

In your editor, type the following JavaScript code in greeter.ts:
function greeter(person) {
    return "Hello, " + person;
}

let user = "Jane User";

document.body.innerHTML = greeter(user);

Compiling your code

We used a .ts extension, but this code is just JavaScript. You could have copy/pasted this straight out of an existing JavaScript app.
At the command line, run the TypeScript compiler:
tsc greeter.ts
The result will be a file greeter.js which contains the same JavaScript that you fed in. We’re up and running using TypeScript in our JavaScript app!

Running your TypeScript web app

Now type the following in greeter.html:
<!DOCTYPE html>
<html>
    <head><title>TypeScript Greeter</title></head>
    <body>
        <script src="greeter.js"></script>
    </body>
</html>
Open greeter.html in the browser to run your first simple TypeScript web application!

For more docs about typescript: www.typescriptlang.org/docs/handbook/typescript-in-5-minutes

No comments:

Post a Comment

My First Day with Uki DN Cohort 1

 "Hello WORLD!"