Skip to content

Commit 05b63d7

Browse files
Merge branch 'prescriptive-react' of https://github.com/Microsoft/TypeScript-Handbook into prescriptive-react
2 parents f352e29 + 8104162 commit 05b63d7

12 files changed

Lines changed: 247 additions & 25 deletions

pages/Advanced Types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ function proxify<T>(o: T): Proxify<T> {
857857
let proxyProps = proxify(props);
858858
```
859859

860-
Note that `Readonly<T>` and `Partial<T>` are so useful, they are included in TypeScript's standard libarary along with `Pick` and `Record`:
860+
Note that `Readonly<T>` and `Partial<T>` are so useful, they are included in TypeScript's standard library along with `Pick` and `Record`:
861861

862862
```ts
863863
type Pick<T, K extends keyof T> = {

pages/Compiler Options.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Option | Type | Default
2222
`--inlineSourceMap` | `boolean` | `false` | Emit a single file with source maps instead of having a separate file.
2323
`--inlineSources` | `boolean` | `false` | Emit the source alongside the sourcemaps within a single file; requires `--inlineSourceMap` or `--sourceMap` to be set.
2424
`--init` | | | Initializes a TypeScript project and creates a `tsconfig.json` file.
25-
`--isolatedModules` | `boolean` | `false` | Unconditionally emit imports for unresolved files.
25+
`--isolatedModules` | `boolean` | `false` | Transpile each file as a separate module (similar to "ts.transpileModule").
2626
`--jsx` | `string` | `"Preserve"` | Support JSX in `.tsx` files: `"React"` or `"Preserve"`. See [JSX](./JSX.md).
2727
`--jsxFactory` | `string` | `"React.createElement"` | Specify the JSX factory function to use when targeting react JSX emit, e.g. `React.createElement` or `h`.
2828
`--lib` | `string[]`| | List of library files to be included in the compilation.<br/>Possible values are: <br/>► `ES5` <br/>► `ES6` <br/>► `ES2015` <br/>► `ES7` <br/>► `ES2016` <br/>► `ES2017` <br/>► `DOM` <br/>► `DOM.Iterable` <br/>► `WebWorker` <br/>► `ScriptHost` <br/>► `ES2015.Core` <br/>► `ES2015.Collection` <br/>► `ES2015.Generator` <br/>► `ES2015.Iterable` <br/>► `ES2015.Promise` <br/>► `ES2015.Proxy` <br/>► `ES2015.Reflect` <br/>► `ES2015.Symbol` <br/>► `ES2015.Symbol.WellKnown` <br/>► `ES2016.Array.Include` <br/>► `ES2017.object` <br/>► `ES2017.SharedMemory` <br/><br/> Note: If `--lib` is not specified a default library is injected. The default library injected is: <br/> ► For `--target ES5`: `DOM,ES5,ScriptHost`<br/> ► For `--target ES6`: `DOM,ES6,DOM.Iterable,ScriptHost`
@@ -31,7 +31,7 @@ Option | Type | Default
3131
`--locale` | `string` | *(platform specific)* | The locale to use to show error messages, e.g. en-us.
3232
`--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.
3333
`--maxNodeModuleJsDepth` | `number` | `0` | The maximum dependency depth to search under node_modules and load JavaScript files. Only applicable with `--allowJs`.
34-
`--module`<br/>`-m` | `string` | `target === "ES6" ? "ES6" : "CommonJS"` | Specify module code generation: `"None"`, `"CommonJS"`, `"AMD"`, `"System"`, `"UMD"`, `"ES6"`, or `"ES2015"`.<br/>► Only `"AMD"` and `"System"` can be used in conjunction with `--outFile`.<br/>► `"ES6"` and `"ES2015"` values may not be used when targeting `"ES5"` or lower.
34+
`--module`<br/>`-m` | `string` | `target === "ES6" ? "ES6" : "CommonJS"` | Specify module code generation: `"None"`, `"CommonJS"`, `"AMD"`, `"System"`, `"UMD"`, `"ES6"`, or `"ES2015"`.<br/>► Only `"AMD"` and `"System"` can be used in conjunction with `--outFile`.<br/>► `"ES6"` and `"ES2015"` values may be used when targeting `"ES5"` or lower.
3535
`--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.
3636
`--newLine` | `string` | *(platform specific)* | Use the specified end of line sequence to be used when emitting files: `"crlf"` (windows) or `"lf"` (unix)."
3737
`--noEmit` | `boolean` | `false` | Do not emit outputs.

pages/Decorators.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
With the introduction of Classes in TypeScript and ES6, there now exist certain scenarios that require additional features to support annotating or modifying classes and class members.
44
Decorators provide a way to add both annotations and a meta-programming syntax for class declarations and members.
5-
Decorators are a [stage 1 proposal](https://github.com/wycats/javascript-decorators/blob/master/README.md) for JavaScript and are available as an experimental feature of TypeScript.
5+
Decorators are a [stage 2 proposal](https://github.com/tc39/proposal-decorators) for JavaScript and are available as an experimental feature of TypeScript.
66

77
> NOTE&emsp; Decorators are an experimental feature that may change in future releases.
88
@@ -163,6 +163,28 @@ function sealed(constructor: Function) {
163163

164164
When `@sealed` is executed, it will seal both the constructor and its prototype.
165165

166+
Next we have a example how to override the constructor.
167+
168+
```ts
169+
function classDecorator<T extends {new(...args:any[]):{}}>(constructor:T) {
170+
return class extends constructor {
171+
newProperty = "new property";
172+
hello = "override";
173+
}
174+
}
175+
176+
@classDecorator
177+
class Greeter {
178+
property = "property";
179+
hello: string;
180+
constructor(m: string) {
181+
this.hello = m;
182+
}
183+
}
184+
185+
console.log(new Greeter("world"));
186+
```
187+
166188
## Method Decorators
167189

168190
A *Method Decorator* is declared just before a method declaration.

pages/Interfaces.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Variables use `const` whereas properties use `readonly`.
143143

144144
# Excess Property Checks
145145

146-
In our first example using interfaces, TypeScript let us pass `{ size: number; label: string; }` to something that only expected a `{ label: string; }`.
146+
In our first example using interfaces, TypeScript lets us pass `{ size: number; label: string; }` to something that only expected a `{ label: string; }`.
147147
We also just learned about optional properties, and how they're useful when describing so-called "option bags".
148148

149149
However, combining the two naively would let you to shoot yourself in the foot the same way you might in JavaScript.

pages/JSX.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ In order to use JSX you must do two things.
1212
1. Name your files with a `.tsx` extension
1313
2. Enable the `jsx` option
1414

15-
TypeScript ships with two JSX modes: `preserve` and `react`.
15+
TypeScript ships with three JSX modes: `preserve`, `react`, and `react-native`.
1616
These modes only affect the emit stage - type checking is unaffected.
1717
The `preserve` mode will keep the JSX as part of the output to be further consumed by another transform step (e.g. [Babel](https://babeljs.io/)).
1818
Additionally the output will have a `.jsx` file extension.
1919
The `react` mode will emit `React.createElement`, does not need to go through a JSX transformation before use, and the output will have a `.js` file extension.
20+
The `react-native` mode is the equivalent of `preserve` in that it keeps all JSX, but the output will instead have a `.js` file extension.
2021

21-
Mode | Input | Output | Output File Extension
22-
-----------|-----------|------------------------------|----------------------
23-
`preserve` | `<div />` | `<div />` | `.jsx`
24-
`react` | `<div />` | `React.createElement("div")` | `.js`
22+
Mode | Input | Output | Output File Extension
23+
---------------|-----------|------------------------------|----------------------
24+
`preserve` | `<div />` | `<div />` | `.jsx`
25+
`react` | `<div />` | `React.createElement("div")` | `.js`
26+
`react-native` | `<div />` | `<div />` | `.js`
2527

2628
You can specify this mode using either the `--jsx` command line flag or the corresponding option in your [tsconfig.json](./tsconfig.json.md) file.
2729

pages/Module Resolution.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Any other import is considered **non-relative**.
3333
Some examples include:
3434

3535
* `import * as $ from "jquery";`
36-
* `import { Component } from "angular2/core";`
36+
* `import { Component } from "@angular/core";`
3737

3838
A relative import is resolved relative to the importing file and *cannot* resolve to an ambient module declaration.
3939
You should use relative imports for your own modules that are guaranteed to maintain their relative location at runtime.
@@ -199,13 +199,13 @@ Value of *baseUrl* is determined as either:
199199

200200
Note that relative module imports are not impacted by setting the baseUrl, as they are always resolved relative to their importing files.
201201

202-
You can find more documentation on baseUrl in [RequireJS](http://requirejs.org/docs/api.html#config-baseUrl) and [SystemJS](https://github.com/systemjs/systemjs/blob/master/docs/overview.md#baseurl) documentation.
202+
You can find more documentation on baseUrl in [RequireJS](http://requirejs.org/docs/api.html#config-baseUrl) and [SystemJS](https://github.com/systemjs/systemjs/blob/master/docs/config-api.md#baseurl) documentation.
203203

204204
### Path mapping
205205

206206
Sometimes modules are not directly located under *baseUrl*.
207207
For instance, an import to a module `"jquery"` would be translated at runtime to `"node_modules\jquery\dist\jquery.slim.min.js"`.
208-
Loaders use a mapping configuration to map module names to files at run-time, see [RequireJs documentation](http://requirejs.org/docs/api.html#config-paths) and [SystemJS documentation](https://github.com/systemjs/systemjs/blob/master/docs/overview.md#map-config).
208+
Loaders use a mapping configuration to map module names to files at run-time, see [RequireJs documentation](http://requirejs.org/docs/api.html#config-paths) and [SystemJS documentation](https://github.com/systemjs/systemjs/blob/master/docs/config-api.md#paths).
209209

210210
The TypeScript compiler supports the declaration of such mappings using `"paths"` property in `tsconfig.json` files.
211211
Here is an example for how to specify the `"paths"` property for `jquery`.

pages/Modules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ export class SomeType { /* ... */ }
628628
export function someFunc() { /* ... */ }
629629
```
630630

631-
Conversly when importing:
631+
Conversely when importing:
632632

633633
### Explicitly list imported names
634634

pages/Variable Declarations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ function f([first, second]: [number, number]) {
472472
console.log(first);
473473
console.log(second);
474474
}
475-
f(input);
475+
f([1, 2]);
476476
```
477477

478478
You can create a variable for the remaining items in a list using the syntax `...`:

pages/declaration files/Do's and Don'ts.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ function reverse(s: String): String;
1717
function reverse(s: string): string;
1818
```
1919

20-
If you're tempted to use the type `Object`, consider using `any` instead.
21-
There is currently no way in TypeScript to specify an object that is "not a primitive".
22-
<!--(Revisit if/when #1809 is implemented)-->
20+
Instead of `Object`, use the non-primitive `object` type ([added in TypeScript 2.2](../release notes/TypeScript 2.2.md#object-type)).
2321

2422
## Generics
2523

pages/release notes/TypeScript 2.1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ var Derived = (function (_super) {
452452
}(Base));
453453
```
454454

455-
> This change entails a break in the behavior of extending built-in classes like `Error`, `Array`, `Map`, etc.. Please see the [extending built-ins breaking change documnetation](https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work) for more details.
455+
> This change entails a break in the behavior of extending built-in classes like `Error`, `Array`, `Map`, etc.. Please see the [extending built-ins breaking change documentation](https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work) for more details.
456456
457457
# Configuration inheritance
458458

0 commit comments

Comments
 (0)