From IT Skills
Jump to: navigation, search

TypeScript restricts JavaScript, which means that not everything possible within JavaScript is possible in TypeScript, sometimes deliberately.

Understanding TypeScript - для швидкого ознайомлення

TypeScript как будущее энтерпрайзного JavaScript

Visual Studio[edit | edit source]

підтримка лише в студіях новіше 2012

Angular#2 tsconfig.json is not supported in VS 2013. and there are no plans to add support for it in the future. VS 2015 does have that

Goals[edit | edit source]

  • the only purpose for TypeScript is to make order with Java-scripts mess
  • to preserve Client-Server model and to exploit TypeScript effectively enums, entity classes, interfaces etc must be actually managed in C# but TypeScript imports them and #Reuse C# definitions

Performance[edit | edit source]

Javascript is an interpreted programming language, but C# is a compiled one, therefore C# is faster. Also performance will depend significantly on the browser selected.

Security[edit | edit source]

TypeScript is just Javascript subset and like all Java-scripts is open sourced for anybody. All sources will go out possession by simple the "File/Save page as..." menu.

Styles[edit | edit source]

Microsoft Coding-guidelines


http://palantir.github.io/tslint/ codelyzer

Module and Namespace[edit | edit source]

!!! use either Namespaces that tend to gather ts-files into ONE js or ONLY modules. Do not mix namespaces and modules in new applications!


anywhere the module keyword was used when declaring an internal module, the namespace keyword can and should be used instead

Namespace[edit | edit source]

!! I have problems. It is compiled but does not work

no import is needed

Just like all global namespace pollution, it can be hard to identify component dependencies, especially in a large application.

External Module[edit | edit source]

A key feature of modules in TypeScript is that two different modules will never contribute names to the same scope.

Global, File (also called external module)

import moduleName = require("moduleFile") or import * as moduleName from "moduleFile";

and better

import {moduleName} from 'moduleFile'

aliases

import polygons = Shapes.Polygons;

Do not use namespaces in modules[edit | edit source]

When first moving to a module-based organization, a common tendency is to wrap exports in an additional layer of namespaces. Modules have their own scope, and only exported declarations are visible from outside the module. With this in mind, namespace provide very little, if any, value when working with modules.

however namespaces are good for global modules.

Class[edit | edit source]

In TypeScript, each member is public by default.

Metadata[edit | edit source]

reflect-metadata[edit | edit source]

The TypeScript support for the prototype of the ES7 Reflection API.

Reflect in ES7.

  • angular team does not use npm reflect-metadata

How get class name in runtime[edit | edit source]

  1. !!! type-guards

https://www.typescriptlang.org/docs/handbook/advanced-types.html

  1. by obj.prototype.constructor.toString() works until code is not minified-uglified and does not work in AOT decorators
    customize uglifying to preserve class names but result size may become 5% larger
  2. to add manually class name as property value like (best of all as partial file that is not implemented yet)
    export class Dashboard {
        static class = 'Dashboard';
        ...
    }
    
    • or add manually class name as decorator value and use package like reflect-metadata
  3. interfere in Typescript transpilation and generate property value with class name automatically

transform plain javascript object to the ES6 classes[edit | edit source]

Interface[edit | edit source]

The JavaScript language doesn't have interfaces. Angular can't see TypeScript interfaces at runtime because they disappear from the transpiled JavaScript.

Inheritance[edit | edit source]

Mixins[edit | edit source]

this is multiple inheritance

Reuse C# definitions[edit | edit source]

Typings[edit | edit source]

Getting type declarations in TypeScript 2.0 will require no tools apart from npm. search at https://aka.ms/types

https://github.com/DefinitelyTyped/DefinitelyTyped

obsolete[edit | edit source]

https://www.npmjs.com/package/typings#quick-start

tsconfig.json[edit | edit source]

  • module Specify module code generation: ‘CommonJS’, ‘amd’, ‘system’, ‘umd’, or ‘es2015’. Only ‘amd’ and ‘system’ can be used in conjunction with --outFile. The ‘es2015’ value may not be used when targeting ES5 or lower.

formats used in #System.config\packages\...\format

System.config[edit | edit source]

The packages node tells SystemJS what to do when it sees a request for a module from the app/ folder.