Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into indexSigs
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRosenwasser committed Apr 14, 2016
2 parents 3c44727 + 69f6ec5 commit 514a67c
Show file tree
Hide file tree
Showing 32 changed files with 669 additions and 24 deletions.
21 changes: 13 additions & 8 deletions pages/Advanced Types.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ For instance, take the following function:
*/
function padLeft(value: string, padding: any) {
if (typeof padding === "number") {
return Array(padding).join(" ") + value;
return Array(padding + 1).join(" ") + value;
}
if (typeof padding === "string") {
return padding + value;
Expand Down Expand Up @@ -163,7 +163,7 @@ function isString(x: any): x is string {

function padLeft(value: string, padding: string | number) {
if (isNumber(padding)) {
return Array(padding).join(" ") + value;
return Array(padding + 1).join(" ") + value;
}
if (isString(padding)) {
return padding + value;
Expand All @@ -179,7 +179,7 @@ That means we could just write these checks inline.
```ts
function padLeft(value: string, padding: string | number) {
if (typeof padding === "number") {
return Array(padding).join(" ") + value;
return Array(padding + 1).join(" ") + value;
}
if (typeof padding === "string") {
return padding + value;
Expand All @@ -206,7 +206,7 @@ interface Padder {
class SpaceRepeatingPadder implements Padder {
constructor(private numSpaces: number) { }
getPaddingString() {
return Array(this.numSpaces).join(" ");
return Array(this.numSpaces + 1).join(" ");
}
}

Expand All @@ -224,7 +224,7 @@ function getRandomPadder() {
}

// Type is SpaceRepeatingPadder | StringPadder
let padder: Padding = getRandomPadder();
let padder: Padder = getRandomPadder();

if (padder instanceof SpaceRepeatingPadder) {
padder; // type narrowed to 'SpaceRepeatingPadder'
Expand All @@ -251,13 +251,13 @@ Here's a simple mixin example:

```ts
function extend<T, U>(first: T, second: U): T & U {
let result = <T & U> {};
let result = <T & U>{};
for (let id in first) {
result[id] = first[id];
(<any>result)[id] = (<any>first)[id];
}
for (let id in second) {
if (!result.hasOwnProperty(id)) {
result[id] = second[id];
(<any>result)[id] = (<any>second)[id];
}
}
return result;
Expand All @@ -269,6 +269,11 @@ class Person {
interface Loggable {
log(): void;
}
class ConsoleLogger implements Loggable {
log() {
// ...
}
}
var jim = extend(new Person("Jim"), new ConsoleLogger());
var n = jim.name;
jim.log();
Expand Down
2 changes: 1 addition & 1 deletion pages/Basic Types.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Introduction

For programs to be useful, we need to be able to work with some of the simplest units of data: numbers, strings, structures, boolean values, and the like.
In TypeScript, we support much the same types as you would expected in JavaScript, with a convenient enumeration type thrown in to help things along.
In TypeScript, we support much the same types as you would expect in JavaScript, with a convenient enumeration type thrown in to help things along.

# Boolean

Expand Down
2 changes: 1 addition & 1 deletion pages/Compiler Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Option | Shorthand | Description
`--skipDefaultLibCheck` | |
`--out` | | DEPRECATED. Use `--outFile` instead.
`--outDir` | | Redirect output structure to the directory.
`--outFile` | | 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.
`--outFile` | | 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](https://github.com/Microsoft/TypeScript/wiki/FAQ#how-do-i-control-file-ordering-in-combined-output---out-).
`--preserveConstEnums` | | 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`<sup>[1]</sup> | | Stylize errors and messages using color and context.
`--removeComments` | | Remove all comments except copy-right header comments beginning with `/*!`
Expand Down
2 changes: 1 addition & 1 deletion pages/Declaration Merging.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ namespace Color {

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.
For information on mimicking class merging, see the [Mixins in TypeScript](./Mixins.md) section.

# Module Augmentation

Expand Down
2 changes: 1 addition & 1 deletion pages/Enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ enum FileAccess {
None,
Read = 1 << 1,
Write = 1 << 2,
ReadWrite = Read | Write
ReadWrite = Read | Write,
// computed member
G = "123".length
}
Expand Down
2 changes: 1 addition & 1 deletion pages/Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ let employeeName = buildName("Joseph", "Samuel", "Lucas", "MacKinzie");
```

*Rest parameters* are treated as a boundless number of optional parameters.
When passing arguments for a rest parameter, can use as many as you want; you can even pass none.
When passing arguments for a rest parameter, you can use as many as you want; you can even pass none.
The compiler will build an array of the arguments passed in with the name given after the ellipsis (`...`), allowing you to use it in your function.

The ellipsis is also used in the type of the function with rest parameters:
Expand Down
4 changes: 2 additions & 2 deletions pages/Generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function loggingIdentity<T>(arg: T): T {
When we do, the compiler will give us an error that we're using the `.length` member of `arg`, but nowhere have we said that `arg` has this member.
Remember, we said earlier that these type variables stand in for any and all types, so someone using this function could have passed in a `number` instead, which does not have a `.length` member.

Let's say that we've actually intended this function to work on arrays of `T` rather that `T` directly. Since we're working with arrays, the `.length` member should be available.
Let's say that we've actually intended this function to work on arrays of `T` rather than `T` directly. Since we're working with arrays, the `.length` member should be available.
We can describe this just like we would create arrays of other types:

```ts
Expand Down Expand Up @@ -221,7 +221,7 @@ alert(stringNumeric.add(stringNumeric.zeroValue, "test"));

Just as with interface, putting the type parameter on the class itself lets us make sure all of the properties of the class are working with the same type.

As we covered in the [Classes section](./Classes.md), a class has two sides to its type: the static side and the instance side.
As we covered in [our section on classes](./Classes.md), a class has two sides to its type: the static side and the instance side.
Generic classes are only generic over their instance side rather than their static side, so when working with classes, static members can not use the class's type parameter.

# Generic Constraints
Expand Down
2 changes: 1 addition & 1 deletion pages/Integrating with Build Tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ npm install -g jspm@beta

_Note: Currently TypeScript support in jspm is in 0.16beta_

More details: [TypeScriptSamples/jspm](https://github.com/Microsoft/TypeScriptSamples/tree/jspm/jspm)
More details: [TypeScriptSamples/jspm](https://github.com/Microsoft/TypeScriptSamples/tree/master/jspm)

# webpack

Expand Down
2 changes: 1 addition & 1 deletion pages/Interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ let digital = createClock(DigitalClock, 12, 17);
let analog = createClock(AnalogClock, 7, 32);
```

Because `createClock`'s first parameter is of type `ClockConstructor`, in `createClock(AnalogClock, 12, 17)`, it checks that `AnalogClock` has the correct constructor signature.
Because `createClock`'s first parameter is of type `ClockConstructor`, in `createClock(AnalogClock, 7, 32)`, it checks that `AnalogClock` has the correct constructor signature.

# Extending Interfaces

Expand Down
1 change: 1 addition & 0 deletions pages/Iterators and Generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ for (let i in list) {

for (let i of list) {
console.log(i); // "4", "5", "6"
}
```

Another distinction is that `for..in` operates on any object; it serves as a way to inspect properties on this object.
Expand Down
4 changes: 2 additions & 2 deletions pages/Modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default class ZipCodeValidator {
```ts
import validator from "./ZipCodeValidator";

let validator = new validator();
let myValidator = new validator();
```

or
Expand Down Expand Up @@ -244,7 +244,7 @@ import zip = require("./ZipCodeValidator");
let strings = ["Hello", "98052", "101"];

// Validators to use
let validator = new zip.ZipCodeValidator();
let validator = new zip();

// Show whether each string passed each validator
strings.forEach(s => {
Expand Down
5 changes: 3 additions & 2 deletions pages/Symbols.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ Just like strings, symbols can be used as keys for object properties.
```ts
let sym = Symbol();

let obj = {};
let obj = {
[sym]: "value"
};

obj[sym] = "value";
console.log(obj[sym]); // "value"
```

Expand Down
4 changes: 2 additions & 2 deletions pages/Type Compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ This comparison process proceeds recursively, exploring the type of each member

# Comparing two functions

While comparing primitive types and object types is relatively straightforward, the question of what kinds of functions should be considered compatible.
While comparing primitive types and object types is relatively straightforward, the question of what kinds of functions should be considered compatible is a bit more involved.
Let's start with a basic example of two functions that differ only in their parameter lists:

```ts
Expand Down Expand Up @@ -261,4 +261,4 @@ These differ only in that assignment extends subtype compatibility with rules to

Different places in the language use one of the two compatibility mechanisms, depending on the situation.
For practical purposes, type compatibility is dictated by assignment compatibility even in the cases of the `implements` and `extends` clauses.
For more information, see the [TypeScript spec](|http://go.microsoft.com/fwlink/?LinkId=267121).
For more information, see the [TypeScript spec](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md).
Loading

0 comments on commit 514a67c

Please sign in to comment.