Using tsconfig.json

Using tsconfig.json By invoking tsc with no input files, in which case the compiler searches for the tsconfig.json file starting in the current directory and continuing up the parent directory chain. By invoking tsc with no input files and a --project (or just -p) command line option that specifies the path of a directory containing a tsconfig.json file. When input files are specified on the command line, tsconfig.json files are ignored.

replace

Symbol.replace A regular expression method that replaces matched substrings of a string. Called by the String.prototype.replace method.

Rest Parameters

Rest Parameters Required, optional, and default parameters all have one thing in common: they talk about one parameter at a time. Sometimes, you want to work with multiple parameters as a group, or you may not know how many parameters a function will ultimately take. In JavaScript, you can work with the arguments directly using the arguments variable that is visible inside every function body. In TypeScript, you can gather these arguments together into a variable: function buildName(firstName:

Using Namespaces

Using Namespaces Namespaces are simply named JavaScript objects in the global namespace. This makes namespaces a very simple construct to use. They can span multiple files, and can be concatenated using --outFile. Namespaces can be a good way to structure your code in a Web Application, with all dependencies included as <script> tags in your HTML page. Just like all global namespace pollution, it can be hard to identify component dependencies, especially in a large application.

Global augmentation

Global augmentation You can also add declarations to the global scope from inside a module: // observable.ts export class Observable<T> { // ... still no implementation ... } declare global { interface Array<T> { toObservable(): Observable<T>; } } Array.prototype.toObservable = function () { // ... } Global augmentations have the same behavior and limits as module augmentations.

search

Symbol.search A regular expression method that returns the index within a string that matches the regular expression. Called by the String.prototype.search method.

Add TypeScript

Add TypeScript The next step is to add a folder for TypeScript. We’ll just call it src.

Classes

Classes Classes work similarly to object literal types and interfaces with one exception: they have both a static and an instance type. When comparing two objects of a class type, only members of the instance are compared. Static members and constructors do not affect compatibility. class Animal { feet: number; constructor(name: string, numFeet: number) { } } class Size { feet: number; constructor(numFeet: number) { } } let a: Animal; let s: Size; a = s; //OK s = a; //OK

Disallowed Merges

Disallowed Merges Not all merges are allowed in TypeScript. Currently, classes can not merge with other classes or with variables. For information on mimicking class merging, see the Mixins in TypeScript section.

Moving to TypeScript Files

Moving to TypeScript Files At this point, you’re probably ready to start using TypeScript files. The first step is to rename one of your .js files to .ts. If your file uses JSX, you’ll need to rename it to .tsx. Finished with that step? Great! You’ve successfully migrated a file from JavaScript to TypeScript! Of course, that might not feel right. If you open that file in an editor with TypeScript support (or if you run tsc --pretty), you might see red squiggles on certain lines. You should thin