diff --git a/README.md b/README.md index 539e83cfb..f938c9662 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Build Status](https://travis-ci.org/Microsoft/TypeScript-Handbook.svg)](https://travis-ci.org/Microsoft/TypeScript-Handbook) -The TypeScript Handbook is a comprehensive guide to the TypeScript language +The TypeScript Handbook is a comprehensive guide to the TypeScript language. +It is meant to be read online at [the TypeScript website](https://www.typescriptlang.org/docs/handbook/basic-types.html) or [directly from this repository](./pages/Basic Types.md). -Please see the [latest TypeScript Language Specification](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md) for more details. +For a more formal description of the language, see the [latest TypeScript Language Specification](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md). diff --git a/pages/Compiler Options.md b/pages/Compiler Options.md index f9835f2ad..7ff79f278 100644 --- a/pages/Compiler Options.md +++ b/pages/Compiler Options.md @@ -3,13 +3,13 @@ Option | Type | Default | Description -----------------------------------------------|-----------|--------------------------------|---------------------------------------------------------------------- `--allowJs` | `boolean` | `true` | Allow JavaScript files to be compiled. -`--allowSyntheticDefaultImports` | `boolean` | `(module === "system")` | Allow default imports from modules with no default export. This does not affect code emit, just typechecking. +`--allowSyntheticDefaultImports` | `boolean` | `module === "system"` | Allow default imports from modules with no default export. This does not affect code emit, just typechecking. `--allowUnreachableCode` | `boolean` | `false` | Do not report errors on unreachable code. `--allowUnusedLabels` | `boolean` | `false` | Do not report errors on unused labels. `--baseUrl` | `string` | | Base directory to resolve non-relative module names. See [Module Resolution documentation](./Module Resolution.md#base-url) for more details. `--charset` | `string` | `"utf8"` | The character set of the input files. `--declaration`
`-d` | `boolean` | `false` | Generates corresponding '.d.ts' file. -`--declarationDir` | `string` | `null` | Output directory for generated declaration files. +`--declarationDir` | `string` | | Output directory for generated declaration files. `--diagnostics` | `boolean` | `false` | Show diagnostic information. `--disableSizeLimit` | `boolean` | `false` | Disable size limitation on JavaScript project. `--emitBOM` | `boolean` | `false` | Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. @@ -26,9 +26,9 @@ Option | Type | Default `--listEmittedFiles` | `boolean` | `false` | Print names of generated files part of the compilation. `--listFiles` | `boolean` | `false` | Print names of files part of the compilation. `--locale` | `string` | *(platform specific)* | The locale to use to show error messages, e.g. en-us. -`--mapRoot` | `string` | `null` | Specifies the location where debugger should locate map files instead of generated locations. Use this flag if the .map files will be located at run-time in a different location than than the .js files. The location specified will be embedded in the sourceMap to direct the debugger where the map files where be located. -`--module`
`-m` | `string` | `(target === 'ES6' ? 'ES6' : 'commonjs')` | Specify module code generation: `'none'`, `'commonjs'`, `'amd'`, `'system'`, `'umd'`, `'es6'`, or `'es2015'`.
► Only `'amd'` and `'system'` can be used in conjunction with `--outFile`.
► `'es6'` and `'es2015'` values may not be used when targeting ES5 or lower. -`--moduleResolution` | `string` | `(module === 'amd' | 'system' | 'ES6' ? 'classic' : 'node')` | Determine how modules get resolved. Either `'node'` for Node.js/io.js style resolution, or `'classic'` (default). See [Module Resolution documentation](Module Resolution.md) for more details. +`--mapRoot` | `string` | | Specifies the location where debugger should locate map files instead of generated locations. Use this flag if the .map files will be located at run-time in a different location than the .js files. The location specified will be embedded in the sourceMap to direct the debugger where the map files will be located. +`--module`
`-m` | `string` | `target === 'ES6' ? 'ES6' : 'commonjs'` | Specify module code generation: `'none'`, `'commonjs'`, `'amd'`, `'system'`, `'umd'`, `'es6'`, or `'es2015'`.
► Only `'amd'` and `'system'` can be used in conjunction with `--outFile`.
► `'es6'` and `'es2015'` values may not be used when targeting ES5 or lower. +`--moduleResolution` | `string` | `module === 'amd' | 'system' | 'ES6' ? 'classic' : 'node'` | Determine how modules get resolved. Either `'node'` for Node.js/io.js style resolution, or `'classic'`. See [Module Resolution documentation](./Module Resolution.md) for more details. `--newLine` | `string` | *(platform specific)* | Use the specified end of line sequence to be used when emitting files: `'crlf'` (windows) or `'lf'` (unix)." `--noEmit` | `boolean` | `false` | Do not emit outputs. `--noEmitHelpers` | `boolean` | `false` | Do not generate custom helper functions like `__extends` in compiled output. @@ -42,13 +42,13 @@ Option | Type | Default `--noResolve` | `boolean` | `false` | Do not add triple-slash references or module import targets to the list of compiled files. `--noUnusedLocals` | `boolean` | `false` | Report errors on unused locals. `--noUnusedParameters` | `boolean` | `false` | Report errors on unused parameters. -~~`--out`~~ | `string` | `null` | DEPRECATED. Use `--outFile` instead. -`--outDir` | `string` | `null` | Redirect output structure to the directory. -`--outFile` | `string` | `null` | Concatenate and emit output to single file. The order of concatenation is determined by the list of files passed to the compiler on the command line along with triple-slash references and imports. See output file order documentation for more details. +~~`--out`~~ | `string` | | DEPRECATED. Use `--outFile` instead. +`--outDir` | `string` | | Redirect output structure to the directory. +`--outFile` | `string` | | Concatenate and emit output to single file. The order of concatenation is determined by the list of files passed to the compiler on the command line along with triple-slash references and imports. See output file order documentation for more details. `paths`[2] | `Object` | | List of path mapping entries for module names to locations relative to the `baseUrl`. See [Module Resolution documentation](./Module Resolution.md#path-mapping) for more details. `--preserveConstEnums` | `boolean` | `false` | Do not erase const enum declarations in generated code. See [const enums documentation](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#94-constant-enum-declarations) for more details. `--pretty`[1] | `boolean` | `false` | Stylize errors and messages using color and context. -`--project`
`-p` | `string` | `null` | Compile a project given a valid configuration file.
The argument can be an file path to a valid JSON configuration file, or a directory path to a directory containing a `tsconfig.json` file.
See [tsconfig.json](./tsconfig.json.md) documentation for more details. +`--project`
`-p` | `string` | | Compile a project given a valid configuration file.
The argument can be an file path to a valid JSON configuration file, or a directory path to a directory containing a `tsconfig.json` file.
See [tsconfig.json](./tsconfig.json.md) documentation for more details. `--reactNamespace` | `string` | `"React"` | Specifies the object invoked for `createElement` and `__spread` when targeting 'react' JSX emit. `--removeComments` | `boolean` | `false` | Remove all comments except copy-right header comments beginning with `/*!` `--rootDir` | `string` | *(common root directory is computed from the list of input files)* | Specifies the root directory of input files. Only use to control the output directory structure with `--outDir`. @@ -56,7 +56,7 @@ Option | Type | Default `--skipLibCheck` | `boolean` | `false` | Don't check a the default library (`lib.d.ts`) file's valitidy. `--skipDefaultLibCheck` | `boolean` | `false` | Don't check a user-defined default library (`*.d.ts`) file's valitidy. `--sourceMap` | `boolean` | `false` | Generates corresponding '.map' file. -`--sourceRoot` | `string` | `null` | Specifies the location where debugger should locate TypeScript files instead of source locations. Use this flag if the sources will be located at run-time in a different location than that at design-time. The location specified will be embedded in the sourceMap to direct the debugger where the source files where be located. +`--sourceRoot` | `string` | | Specifies the location where debugger should locate TypeScript files instead of source locations. Use this flag if the sources will be located at run-time in a different location than that at design-time. The location specified will be embedded in the sourceMap to direct the debugger where the source files will be located. `--strictNullChecks` | `boolean` | `false` | In strict null checking mode, the `null` and `undefined` values are not in the domain of every type and are only assignable to themselves and `any` (the one exception being that `undefined` is also assignable to `void`). `--stripInternal`[1] | `boolean` | `false` | Do not emit declarations for code that has an `/** @internal */` JSDoc annotation. `--suppressExcessPropertyErrors` | `boolean` | `false` | Suppress excess property checks for object literals. diff --git a/pages/Keywords.md b/pages/Keywords.md new file mode 100644 index 000000000..a827b8745 --- /dev/null +++ b/pages/Keywords.md @@ -0,0 +1,173 @@ +# Keywords + +Keyword | Syntax | Category | Description | External links +---|---|---|---|--- +| `abstract` | `abstract class` | [Classes](#classes) | [Abstract classes (cannot be instantiated; must be inherited)](Classes.md#abstract-classes) | | +| `abstract` | `abstract` _member_ | [Classes](#classes) | [Inheriting classes must implement this method/property](Classes.md#abstract-classes) | | +| `any` | | [Primitive types](#primitive-types) | [Describes a type unknown at design time](Basic%20Types.md#any) | | +| `as` | | [Type operation](#type-operation) | [Type assertion](Basic%20Types.md#type-assertions) | | +| `as` | `import {`_item_ `as` _name_`} from "`_path_`"`
`import * as `_name_` from "` _path_ `"` | [Environment/modules](#environment-modules) | [Module import renaming](Modules.md#import) | | +| `as` | `export as namespace` _namespace_ | [Environment/modules](#environment-modules) | [UMD/isomorphic modules](Modules.md#umd-modules) | | +| `async` | | [Functions](#functions) | Marks function as asynchronous | [ES draft](http://tc39.github.io/ecmascript-asyncawait/), [PR#1664](https://github.com/Microsoft/TypeScript/issues/1664), [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#68-asynchronous-functions) | +| `await` | | [Functions](#functions) | Waits for value within an asynchronous function | [ES draft](http://tc39.github.io/ecmascript-asyncawait/), [PR#1664](https://github.com/Microsoft/TypeScript/issues/1664), [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#68-asynchronous-functions) | +| `boolean` | | [Primitive types](#primitive-types) | [`boolean` type](Basic%20Types.md#boolean) | | +| `break` | | [Control flow](#control-flow) | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break) | +| `continue` | | [Control flow](#control-flow) | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue) | +| `class` | | [Classes](#classes) | [Class declaration/expression](Classes.md) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) | +| `const` | | [Variable declaration](#variable-declaration) | [`const` declaration](Variable%20Declarations.md#const-declarations) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const) | +| `const` | `const enum` | [User-defined-type modifier](#user-defined-type-modifier) | [Forces a const enum](Enums.md) | | +| `configurable` | | [Property descriptors](#property-descriptors) | Can property descriptor be changed | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) | +| `constructor` | | [Classes](#classes) | [Constructor functions](Classes.md#constructor-functions) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor) | +| `debugger` | | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger) | +| `declare` | | [Environment/modules](#environment-modules) | [Ambient declarations](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#12-ambients) | | +| `default` | | [Control flow](#control-flow) | Part of `switch...case` | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/default) | +| `default` | `export default` _expr_ | [Environment/modules](#environment-modules) | [Default exports](Modules.md#default-exports) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) | +| `delete` | | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete) | +| `do`...`while` | | [Control flow](#control-flow) | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/do...while) | +| `enum` | | [User-defined type](#user-defined-type) | [Defines a set of named values](Enums.md) | | +| `enumerable` | | [Property descriptors](#property-descriptors) | Is visible when properties are enumerated | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) | +| `export` | | [Environment/modules](#environment-modules) | Allow access to elements from outside the [module](Modules.md#export) or [namespace](Namespaces.md#namespacing) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) | +| `extends` | | [User-defined-type modifier](#user-defined-type-modifier) | [Inheritance](Classes.md#inheritance) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class) | +| `false` | | [Literal](#literal) | | [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#322-the-boolean-type) | +| `for` | | [Control flow](#control-flow) | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for) | +| `for`...`in` | | [Control flow](#control-flow) | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in) | +| `for`...`of` | | [Control flow](#control-flow) | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of) | +| `from` | `import` _importExpr_ `from "`_path_`"` | [Environment/modules](#environment-modules) | [Location of imported module](Modules.md#import) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) | +| `function` | | [Functions](#functions) | [Function declaration](Functions.md#functions) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function) | +| `get` | | [Property descriptors](#property-descriptors) | Getter | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) | +| `get` | | [Classes](#classes) | [Getter](Classes.md#accessors) | | +| `if`...`else` | | [Control flow](#control-flow) | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else) | +| `implements` | _class_ `implements` _interface_ | [User-defined-type modifier](#user-defined-type-modifier) | [Class must match the shape of the interface](Interfaces.md#implementing-an-interface) | | +| `import` | | [Environment/modules](#environment-modules) | [Enable access to a module's exported elements](Modules.md#import) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) | +| `import` | `import` _alias_ `=` _symbol_ | [Environment/modules](#environment-modules) | [Define an alias of _symbol_](Namespaces.md#aliases) | | +| `instanceof` | _expr_ `instanceof` _constructor_ | [Type operation](#type-operation) | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof) | +| `interface` | | [User-defined type](#user-defined-type) | [Defines a type by its shape (structural typing)](Interfaces.md) | | +| `is` | _parameter_ `is` _type_ | [Type annotation](#type-annotation) | [User-defined type guards](Advanced%20Types.md#user-defined-type-guards) | | +| `let` | | [Variable declaration](#variable-declaration) | [`let` declaration](Variable%20Declarations.md#let-declarations) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let) | +| `module` | | [Environment/modules](#environment-modules) | [Define an ambient module](Modules.md#ambient-modules) | | +| `namespace` | | [Environment/modules](#environment-modules) | [Associates the contained elements with the specified namespace](Namespaces.md) | | +| `never` | | [Primitive types](#primitive-types) | [`never` type](https://github.com/Microsoft/TypeScript/wiki/What%27s-new-in-TypeScript#the-never-type) | | +| `new` | | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new) | +| `new` | | [Type annotation](#type-annotation) | Constructor function type | [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#389-constructor-type-literals) | +| `null` | | [Literal](#literal) | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null) | +| `null` | | [Primitive types](#primitive-types) | [`null` type](Basic%20Types.md#null-and-undefined) | | +| `number` | | [Primitive types](#primitive-types) | [`number` type](Basic%20Types.md#number) | | +| `private` | | [Accessibility modifier](#accessibility-modifier) | [Property can be used only from its containing class](Classes.md#understanding-private) | | +| `protected` | | [Accessibility modifier](#accessibility-modifier) | [Property can only be used in its containing class, or by classes which inherit from the containing class](Classes.md#understanding-protected) | | +| `public` | | [Accessibility modifier](#accessibility-modifier) | [Property can be used from outside its containing class](Classes.md#public-by-default) | | +| `readonly` | | [Member modifier](#member-modifier) | [Property's value can be read, but not written to](Classes.md#readonly-modifier) | | +| `require` | `import` _name_ `= require("`_path_`")` | [Environment/modules](#environment-modules) | [Import the custom object defined in a module with `export =`](Modules.md#export--and-import--require) | | +| `return` | | [Functions](#functions) | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return) | +| `set` | | [Property descriptors](#property-descriptors) | Setter | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) | +| `set` | | [Classes](#classes) | [Setter](Classes.md#accessors) | | +| `static` | | [Classes](#classes) | [Static properties](Classes.md#static-properties) | | +| `string` | | [Primitive types](#primitive-types) | [`string` type](Basic%20Types.md#string) | | +| `super` | | [Classes](#classes) | Reference to properties / constructor of the base class | [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#49-the-super-keyword), [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Super_class_calls_with_super) | +| `switch...case` | | [Control flow](#control-flow) | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch) | +| `symbol` | | [Primitive types](#primitive-types) | [`symbol` type](Symbols.md) | | +| `this` | | [Functions](#functions) | | [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#42-the-this-keyword), [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this) | +| `this` | | [Type annotation](#type-annotation) | Represents the actual type ([derived or implemented](Advanced%20Types.md#polymorphic-this-types)) within a (base) class or interface | | +| `this` | `(this: ` _annotation_) | [Functions](#functions) | [`this` parameter](Functions.md#this-parameters) | | +| `this` | `this is` _T_ | [Classes](#classes) | [`this`-based type guards](https://github.com/Microsoft/TypeScript/wiki/What%27s-new-in-TypeScript#this-based-type-guards) | | +| `true` | | [Literal](#literal) | | [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#322-the-boolean-type) | +| `try`...`catch`...`finally` | | [Control flow](#control-flow) | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch) | +| `type` | | [User-defined type](#user-defined-type) | [Type alias](Advanced%20Types.md#type-aliases) | | +| `typeof` | | [Type operation](#type-operation) | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof) | +| `typeof` | | [Type annotation](#type-annotation) | Copies the type of an existing identifier | [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#3810-type-queries) | +| `undefined` | | [Literal](#literal) | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined) | +| `undefined` | | [Primitive types](#primitive-types) | [`undefined` type](Basic%20Types.md#null-and-undefined) | | +| `value` | | [Property descriptors](#property-descriptors) | Value associated with a property | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) | +| `var` | | [Variable declaration](#variable-declaration) | [`var` declaration](Variable%20Declarations.md#var-declarations) | | +| `void` | | | Evaluates expression but returns `undefined` | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void) | +| `void` | | [Primitive types](#primitive-types) | [`void` type](Basic%20Types.md#void) | | +| `while` | | [Control flow](#control-flow) | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while) | +| `writable` | | [Property descriptors](#property-descriptors) | Can property be written to | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) | +| `yield` | | [Functions](#functions) | Returns next value of generator function | [PR#2783](https://github.com/Microsoft/TypeScript/issues/2873), [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#67-generator-functions) | + +--- + +### By category + +Category | Keyword | Syntax | Description | External links +---|---|---|---|--- +|
Literal
| `false` | | | [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#322-the-boolean-type) | +| Literal | `null` | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null) | +| Literal | `true` | | | [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#322-the-boolean-type) | +| Literal | `undefined` | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined) | +|
Variable declaration
| `const` | | [`const` declaration](Variable%20Declarations.md#const-declarations) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const) | +| Variable declaration | `let` | | [`let` declaration](Variable%20Declarations.md#let-declarations) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let) | +| Variable declaration | `var` | | [`var` declaration](Variable%20Declarations.md#var-declarations) | | +|
Control flow
| `break` | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break) | +| Control flow | `continue` | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue) | +| Control flow | `default` | | Part of `switch...case` | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/default) | +| Control flow | `do`...`while` | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/do...while) | +| Control flow | `for` | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for) | +| Control flow | `for`...`in` | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in) | +| Control flow | `for`...`of` | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of) | +| Control flow | `if`...`else` | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else) | +| Control flow | `switch...case` | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch) | +| Control flow | `try`...`catch`...`finally` | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch) | +| Control flow | `while` | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while) | +|
Functions
| `async` | | Marks function as asynchronous | [ES draft](http://tc39.github.io/ecmascript-asyncawait/), [PR#1664](https://github.com/Microsoft/TypeScript/issues/1664), [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#68-asynchronous-functions) | +| Functions | `await` | | Waits for value within an asynchronous function | [ES draft](http://tc39.github.io/ecmascript-asyncawait/), [PR#1664](https://github.com/Microsoft/TypeScript/issues/1664), [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#68-asynchronous-functions) | +| Functions | `function` | | [Function declaration](Functions.md#functions) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function) | +| Functions | `return` | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return) | +| Functions | `this` | | | [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#42-the-this-keyword), [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this) | +| Functions | `this` | `(this: ` _annotation_) | [`this` parameter](Functions.md#this-parameters) | | +| Functions | `yield` | | Returns next value of generator function | [PR#2783](https://github.com/Microsoft/TypeScript/issues/2873), [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#67-generator-functions) | +|
Property descriptors
| `configurable` | | Can property descriptor be changed | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) | +| Property descriptors | `enumerable` | | Is visible when properties are enumerated | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) | +| Property descriptors | `get` | | Getter | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) | +| Property descriptors | `set` | | Setter | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) | +| Property descriptors | `value` | | Value associated with a property | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) | +| Property descriptors | `writable` | | Can property be written to | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) | +| | `debugger` | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger) | +| | `delete` | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete) | +| | `new` | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new) | +| | `void` | | Evaluates expression but returns `undefined` | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void) | +|
Primitive types
| `any` | | [Describes a type unknown at design time](Basic%20Types.md#any) | | +| Primitive types | `boolean` | | [`boolean` type](Basic%20Types.md#boolean) | | +| Primitive types | `never` | | [`never` type](https://github.com/Microsoft/TypeScript/wiki/What%27s-new-in-TypeScript#the-never-type) | | +| Primitive types | `null` | | [`null` type](Basic%20Types.md#null-and-undefined) | | +| Primitive types | `number` | | [`number` type](Basic%20Types.md#number) | | +| Primitive types | `string` | | [`string` type](Basic%20Types.md#string) | | +| Primitive types | `symbol` | | [`symbol` type](Symbols.md) | | +| Primitive types | `undefined` | | [`undefined` type](Basic%20Types.md#null-and-undefined) | | +| Primitive types | `void` | | [`void` type](Basic%20Types.md#void) | | +|
Type annotation
| `is` | _parameter_ `is` _type_ | [User-defined type guards](Advanced%20Types.md#user-defined-type-guards) | | +| Type annotation | `new` | | Constructor function type | [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#389-constructor-type-literals) | +| Type annotation | `this` | | Represents the actual type ([derived or implemented](Advanced%20Types.md#polymorphic-this-types)) within a (base) class or interface | | +| Type annotation | `typeof` | | Copies the type of an existing identifier | [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#3810-type-queries) | +|
Type operation
| `as` | | [Type assertion](Basic%20Types.md#type-assertions) | | +| Type operation | `instanceof` | _expr_ `instanceof` _constructor_ | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof) | +| Type operation | `typeof` | | | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof) | +|
Environment/modules
| `as` | `import {`_item_ `as` _name_`} from "`_path_`"`
`import * as `_name_` from "` _path_ `"` | [Module import renaming](Modules.md#import) | | +| Environment/modules | `as` | `export as namespace` _namespace_ | [UMD/isomorphic modules](Modules.md#umd-modules) | | +| Environment/modules | `declare` | | [Ambient declarations](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#12-ambients) | | +| Environment/modules | `default` | `export default` _expr_ | [Default exports](Modules.md#default-exports) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) | +| Environment/modules | `export` | | Allow access to elements from outside the [module](Modules.md#export) or [namespace](Namespaces.md#namespacing) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) | +| Environment/modules | `from` | `import` _importExpr_ `from "`_path_`"` | [Location of imported module](Modules.md#import) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) | +| Environment/modules | `import` | | [Enable access to a module's exported elements](Modules.md#import) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) | +| Environment/modules | `import` | `import` _alias_ `=` _symbol_ | [Define an alias of _symbol_](Namespaces.md#aliases) | | +| Environment/modules | `module` | | [Define an ambient module](Modules.md#ambient-modules) | | +| Environment/modules | `namespace` | | [Associates the contained elements with the specified namespace](Namespaces.md) | | +| Environment/modules | `require` | `import` _name_ `= require("`_path_`")` | [Import the custom object defined in a module with `export =`](Modules.md#export--and-import--require) | | +|
User-defined type
| `enum` | | [Defines a set of named values](Enums.md) | | +| User-defined type | `interface` | | [Defines a type by its shape (structural typing)](Interfaces.md) | | +| User-defined type | `type` | | [Type alias](Advanced%20Types.md#type-aliases) | | +|
User-defined-type modifier
| `const` | `const enum` | [Forces a const enum](Enums.md) | | +| User-defined-type modifier | `extends` | | [Inheritance](Classes.md#inheritance) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class) | +| User-defined-type modifier | `implements` | _class_ `implements` _interface_ | [Class must match the shape of the interface](Interfaces.md#implementing-an-interface) | | +|
Classes
| `abstract` | `abstract class` | [Abstract classes (cannot be instantiated; must be inherited)](Classes.md#abstract-classes) | | +| Classes | `abstract` | `abstract` _member_ | [Inheriting classes must implement this method/property](Classes.md#abstract-classes) | | +| Classes | `class` | | [Class declaration/expression](Classes.md) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) | +| Classes | `constructor` | | [Constructor functions](Classes.md#constructor-functions) | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor) | +| Classes | `get` | | [Getter](Classes.md#accessors) | | +| Classes | `set` | | [Setter](Classes.md#accessors) | | +| Classes | `static` | | [Static properties](Classes.md#static-properties) | | +| Classes | `super` | | Reference to properties / constructor of the base class | [spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#49-the-super-keyword), [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Super_class_calls_with_super) | +| Classes | `this` | `this is` _T_ | [`this`-based type guards](https://github.com/Microsoft/TypeScript/wiki/What%27s-new-in-TypeScript#this-based-type-guards) | | +|
Accessibility modifier
| `private` | | [Property can be used only from its containing class](Classes.md#understanding-private) | | +| Accessibility modifier | `protected` | | [Property can only be used in its containing class, or by classes which inherit from the containing class](Classes.md#understanding-protected) | | +| Accessibility modifier | `public` | | [Property can be used from outside its containing class](Classes.md#public-by-default) | | +|
Member modifier
| `readonly` | | [Property's value can be read, but not written to](Classes.md#readonly-modifier) | | \ No newline at end of file diff --git a/pages/Modules.md b/pages/Modules.md index 3a004cca6..f04c0c165 100644 --- a/pages/Modules.md +++ b/pages/Modules.md @@ -554,7 +554,7 @@ For example: ##### math-lib.d.ts ```ts -export const isPrime(x: number): boolean;' +export const isPrime(x: number): boolean; export as namespace mathLib; ``` diff --git a/pages/declaration files/Introduction.md b/pages/declaration files/Introduction.md index de3cc423d..ba31286ac 100644 --- a/pages/declaration files/Introduction.md +++ b/pages/declaration files/Introduction.md @@ -36,7 +36,7 @@ For seasoned authors interested in the underlying mechanics of how declaration f ## `/templates` -In the `templates` directory, you'll find a number of declaration files that serve as a useful starting point +In the [`templates`](https://github.com/Microsoft/TypeScript-Handbook/tree/master/pages/declaration%20files/templates) directory, you'll find a number of declaration files that serve as a useful starting point when writing a new file. Refer to the documentation in [Library Structures](./Library Structures.md) to figure out which template file to use. diff --git a/pages/declaration files/Library Structures.md b/pages/declaration files/Library Structures.md index 414e97fa5..9b75bb5da 100644 --- a/pages/declaration files/Library Structures.md +++ b/pages/declaration files/Library Structures.md @@ -4,7 +4,7 @@ Broadly speaking, the way you *structure* your declaration file depends on how t There are many ways of offering a library for consumption in JavaScript, and you'll need to write your declaration file to match it. This guide covers how to identify common library patterns, and how to write declaration files which correspond to that pattern. -Each type of major library structuring pattern has a corresponding file in the [`templates`](./templates) directory. +Each type of major library structuring pattern has a corresponding file in the [`templates`](https://github.com/Microsoft/TypeScript-Handbook/tree/master/pages/declaration%20files/templates) directory. You can start with these templates to help you get going faster. # Identifying Kinds of Libraries @@ -76,7 +76,7 @@ However, libraries that are small and require the DOM (or have *no* dependencies ### Global Library Template -The template file [`global.d.ts`](./templates/global.d.ts) defines an example library `myLib`. +The template file [`global.d.ts`](https://github.com/Microsoft/TypeScript-Handbook/tree/master/pages/declaration%20files/templates/global.d.ts) defines an example library `myLib`. Be sure to read the ["Preventing Name Conflicts" footnote](#preventing-name-conflicts). ## Modular Libraries @@ -176,9 +176,9 @@ Examples include [jQuery](https://jquery.com/), [Moment.js](http://momentjs.com/ ### Template There are three templates available for modules, - [`module.d.ts`](./templates/module.d.ts), [`module-class.d.ts`](./templates/module-class.d.ts) and [`module-function.d.ts`](./templates/module-function.d.ts). + [`module.d.ts`](https://github.com/Microsoft/TypeScript-Handbook/tree/master/pages/declaration%20files/templates/module.d.ts), [`module-class.d.ts`](https://github.com/Microsoft/TypeScript-Handbook/tree/master/pages/declaration%20files/templates/module-class.d.ts) and [`module-function.d.ts`](https://github.com/Microsoft/TypeScript-Handbook/tree/master/pages/declaration%20files/templates/module-function.d.ts). -Use [`module-function.d.ts`](./templates/module-function.d.ts) if your module can be *called* like a function: +Use [`module-function.d.ts`](https://github.com/Microsoft/TypeScript-Handbook/tree/master/pages/declaration%20files/templates/module-function.d.ts) if your module can be *called* like a function: ```ts var x = require("foo"); @@ -188,7 +188,7 @@ var y = x(42); Be sure to read the [footnote "The Impact of ES6 on Module Call Signatures"](#the-impact-of-es6-on-module-plugins) -Use [`module-class.d.ts`](./templates/module-class.d.ts) if your module can be *constructed* using `new`: +Use [`module-class.d.ts`](https://github.com/Microsoft/TypeScript-Handbook/tree/master/pages/declaration%20files/templates/module-class.d.ts) if your module can be *constructed* using `new`: ```ts var x = require("bar"); @@ -198,7 +198,7 @@ var y = new x("hello"); The same [footnote](#the-impact-of-es6-on-module-plugins) applies to these modules. -If your module is not callable or constructable, use the [`module.d.ts`](./templates/module.d.ts) file. +If your module is not callable or constructable, use the [`module.d.ts`](https://github.com/Microsoft/TypeScript-Handbook/tree/master/pages/declaration%20files/templates/module.d.ts) file. ## *Module Plugin* or *UMD Plugin* @@ -209,7 +209,7 @@ For the purposes of writing a declaration file, you'll write the same code wheth ### Template -Use the [`module-plugin.d.ts`](./templates/module-plugin.d.ts) template. +Use the [`module-plugin.d.ts`](https://github.com/Microsoft/TypeScript-Handbook/tree/master/pages/declaration%20files/templates/module-plugin.d.ts) template. ## *Global Plugin* @@ -236,7 +236,7 @@ console.log(y.reverseAndSort()); ### Template -Use the [`global-plugin.d.ts`](./templates/global-plugin.d.ts) template. +Use the [`global-plugin.d.ts`](https://github.com/Microsoft/TypeScript-Handbook/tree/master/pages/declaration%20files/templates/global-plugin.d.ts) template. ## *Global-modifying Modules* @@ -269,7 +269,7 @@ console.log(y.reverseAndSort()); ### Template -Use the [`global-modifying-module.d.ts`](./templates/global-modifying-module.d.ts) template. +Use the [`global-modifying-module.d.ts`](https://github.com/Microsoft/TypeScript-Handbook/tree/master/pages/declaration%20files/templates/global-modifying-module.d.ts) template. # Consuming Dependencies