split

Symbol.split A regular expression method that splits a string at the indices that match the regular expression. Called by the String.prototype.split method.

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.

Schema

Schema Schema can be found at: http://json.schemastore.org/tsconfig

Sections

Sections The guide is broken down into the following sections.

Return Types of Callbacks

Return Types of Callbacks Don’t use the return type any for callbacks whose value will be ignored: /* WRONG */ function fn(x: () => any) { x(); } Do use the return type void for callbacks whose value will be ignored: /* OK */ function fn(x: () => void) { x(); } Why: Using void is safer because it prevents you from accidently using the return value of x in an unchecked way: function fn(x: () => void) { var k = x(); // oops! meant to do something else k.doSomething(); // error,

Scoping rules

Scoping rules var declarations have some odd scoping rules for those used to other languages. Take the following example: function f(shouldInitialize: boolean) { if (shouldInitialize) { var x = 10; } return x; } f(true); // returns '10' f(false); // returns 'undefined' Some readers might do a double-take at this example. The variable x was declared within the if block, and yet we were able to access it from outside that block. That’s because var declarations are accessible anywher

Searching

Searching For the most part, type declaration packages should always have the same name as the package name on npm, but prefixed with @types/, but if you need, you can check out https://aka.ms/types to find the package for your favorite library. Note: if the declaration file you are searching for is not present, you can always contribute one back and help out the next developer looking for it. Please see the DefinitelyTyped contribution guidelines page for details.

Reusable Types (Interfaces)

Reusable Types (Interfaces) Documentation When specifying a greeting, you must pass a GreetingSettings object. This object has the following properties: - greeting: Mandatory string - duration: Optional length of time (in milliseconds) - color: Optional string, e.g. ‘#ff00ff’ Code greet({ greeting: "hello world", duration: 4000 }); Declaration Use an interface to define a type with properties. interface GreetingSettings { greeting: string; duration?: number; color?: string; } decl

Reusable Types (Type Aliases)

Reusable Types (Type Aliases) Documentation Anywhere a greeting is expected, you can provide a string, a function returning a string, or a Greeter instance. Code function getGreeting() { return "howdy"; } class MyGreeter extends Greeter { } greet("hello"); greet(getGreeting); greet(new MyGreeter()); Declaration You can use a type alias to make a shorthand for a type: type GreetingLike = string | (() => string) | Greeting; declare function greet(g: GreetingLike): void;

React integration

React integration To use JSX with React you should use the React typings. These typings define the JSX namespace appropriately for use with React. /// <reference path="react.d.ts" /> interface Props { foo: string; } class MyComponent extends React.Component<Props, {}> { render() { return <span>{this.props.foo}</span> } } <MyComponent foo="bar" />; // ok <MyComponent foo={0} />; // error