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

More umd #328

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0264979
Add private and protected constructor topic
AbubakerB Feb 18, 2016
0f8feff
Addressed PR
AbubakerB Feb 19, 2016
05bd50c
Removed whitespace
AbubakerB Feb 19, 2016
97047b5
Merge pull request #158 from AbubakerB/classesModifierUpdate
DanielRosenwasser Feb 19, 2016
26e1ff6
Merge branch 'master' into release-2.0
DanielRosenwasser Feb 27, 2016
8cf255e
Merge branch 'master' into release-2.0
mhegazy Mar 22, 2016
68ae0c3
Merge branch 'master' into release-2.0
mhegazy Mar 22, 2016
e2b5c9b
Add post 1.8 module resolution updates
mhegazy Mar 22, 2016
8061473
Merge pull request #200 from Microsoft/moduleResolutionRlease2.0
mhegazy Mar 22, 2016
3cf4c2e
Merge branch 'master' into release-2.0
DanielRosenwasser Apr 9, 2016
4761af5
docs(Module Resolution): update --traceModuleResolution to --traceRes…
IgorMinar Apr 13, 2016
92420eb
Merge pull request #249 from IgorMinar/patch-1
DanielRosenwasser Apr 14, 2016
fe44867
Fix small typo
vkrol Apr 25, 2016
7611960
Merge pull request #259 from vkrol/patch-1
sandersn Apr 25, 2016
e942d1d
Merge branch 'master' into release-2.0
mhegazy Jun 13, 2016
9be3437
Merge branch 'master' into release-2.0
mhegazy Jun 13, 2016
4c93963
Revert "Remove TS 2.0 flags"
mhegazy Jun 13, 2016
90d6c6f
Add new compiler options
mhegazy Jun 14, 2016
95e78f9
Sort alphapitaclly
mhegazy Jun 14, 2016
e48d0ad
Add MSBuild mappings
mhegazy Jun 14, 2016
40d4a96
Update message to use MSBuild instead of VS
mhegazy Jun 14, 2016
06a19b6
Formatting
mhegazy Jun 14, 2016
c08fbe8
Update Compiler Options.md
DanielRosenwasser Jun 14, 2016
0bc7f83
Merge pull request #300 from Microsoft/updateCompilerOptions
mhegazy Jun 15, 2016
8224a6a
Update Compiler Options in MSBuild.md
mhegazy Jun 15, 2016
c3b45c7
Fix https://github.com/Microsoft/TypeScript-Handbook/issues/306
mhegazy Jun 21, 2016
ab93457
Added a section on the 'null' and 'undefined' types.
DanielRosenwasser Jun 23, 2016
846021d
Fixed trailing spaces.
DanielRosenwasser Jun 23, 2016
dd7c6d9
Rephrasing.
DanielRosenwasser Jun 23, 2016
0779597
Update Basic Types.md
DanielRosenwasser Jun 23, 2016
64c3564
Merge pull request #314 from Microsoft/nullUndefined
DanielRosenwasser Jun 24, 2016
df1ae40
Add documentation for shorthand ambient modules
Jun 24, 2016
cb1211b
Document wildcard module declarations
Jun 24, 2016
7b2c80a
Fix typo
Jun 24, 2016
2b7b9bf
Merge pull request #317 from Microsoft/shorthand_ambient_modules
Jun 24, 2016
c22c6a4
Respond to PR comment
Jun 24, 2016
9f3467b
Merge pull request #318 from Microsoft/wildcards
Jun 24, 2016
b1e5f80
Document UMD module definitions
Jun 24, 2016
edc8a21
Merge pull request #322 from Microsoft/umd
Jun 24, 2016
c4061f5
Document readonly
sandersn Jun 24, 2016
8e13006
Minor fix to parameter properties update
sandersn Jun 24, 2016
c9dda1c
Fix missing newline lint
sandersn Jun 24, 2016
56eb653
Remove `(default)` marker from classic module loader
mhegazy Jun 24, 2016
301cce0
Note that get/no-set accessors are readonly
sandersn Jun 24, 2016
39e298d
Merge pull request #323 from Microsoft/readonly
sandersn Jun 24, 2016
d0a9bb2
Add description of UMD modules to `Modules.md` in addition to `Writin…
Jun 27, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pages/Basic Types.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,27 @@ Declaring variables of type `void` is not useful because you can only assign `un
let unusable: void = undefined;
```

# Null and Undefined

In TypeScript, both `undefined` and `null` actually have their own types named `undefined` and `null` respectively.
Much like `void`, they're not extremely useful on their own:

```ts
// Not much else we can assign to these variables!
let u: undefined = undefined;
let n: null = null;
```

By default `null` and `undefined` are subtypes of all other types.
That means you can assign `null` and `undefined` to something like `number`.

However, when using the `--strictNullChecks` flag, `null` and `undefined` are only assignable to `void` and their respective types.
This helps avoid *many* common errors.
In cases where you want to pass in either a `string` or `null` or `undefined`, you can use the union type `string | null | undefined`.
Once again, more on union types later on.

> As a note: we encourage the use of `--strictNullChecks` when possible, but for the purposes of this handbook, we will assume it is turned off.

# Type assertions

Sometimes you'll end up in a situation where you'll know more about a value than TypeScript does.
Expand Down
68 changes: 58 additions & 10 deletions pages/Classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,27 +189,70 @@ console.log(howard.name); // error

Notice that while we can't use `name` from outside of `Person`, we can still use it from within an instance method of `Employee` because `Employee` derives from `Person`.

A constructor may also be marked `protected`.
This means that the class cannot be instantiated outside of its containing class, but can be extended. For example,

```ts
class Person {
protected name: string;
protected constructor(theName: string) { this.name = theName; }
}

// Employee can extend Person
class Employee extends Person {
private department: string;

constructor(name: string, department: string) {
super(name);
this.department = department;
}

public getElevatorPitch() {
return `Hello, my name is ${this.name} and I work in ${this.department}.`;
}
}

let howard = new Employee("Howard", "Sales");
let john = new Person("John"); // Error: The 'Person' constructor is protected
```

# Readonly modifier

You can make properties readonly by using the `readonly` keyword.
Readonly properties must be initialized at their declaration or in the constructor.

```ts
class Octopus {
readonly name: string;
readonly numberOfLegs: number = 8;
constructor (theName: string) {
this.name = theName;
}
}
let dad = new Octopus("Man with the 8 strong legs");
dad.name = "Man with the 3-piece suit"; // error! name is readonly.
```

## Parameter properties

In our last example, we had to declare a private member `name` and a constructor parameter `theName`, and we then immediately set `name` to `theName`.
In our last example, we had to declare a readonly member `name` and a constructor parameter `theName` in the `Octopus` class, and we then immediately set `name` to `theName`.
This turns out to be a very common practice.
*Parameter properties* let you create and initialize a member in one place.
Here's a further revision of the previous `Animal` class using a parameter property:
Here's a further revision of the previous `Octopus` class using a parameter property:

```ts
class Animal {
constructor(private name: string) { }
move(distanceInMeters: number) {
console.log(`${this.name} moved ${distanceInMeters}m.`);
class Octopus {
readonly numberOfLegs: number = 8;
constructor(readonly name: string) {
}
}
```

Notice how we dropped `theName` altogether and just use the shortened `private name: string` parameter on the constructor to create and initialize the `name` member.
Notice how we dropped `theName` altogether and just use the shortened `readonly name: string` parameter on the constructor to create and initialize the `name` member.
We've consolidated the declarations and assignment into one location.

Parameter properties are declared by prefixing a constructor parameter with an accessibility modifier.
Using `private` for a parameter property declares and initializes a private member; likewise, the same is done for `public` and `protected`.
Parameter properties are declared by prefixing a constructor parameter with an accessibility modifier or `readonly`, or both.
Using `private` for a parameter property declares and initializes a private member; likewise, the same is done for `public`, `protected`, and `readonly`.

# Accessors

Expand Down Expand Up @@ -266,7 +309,12 @@ if (employee.fullName) {

To prove to ourselves that our accessor is now checking the passcode, we can modify the passcode and see that when it doesn't match we instead get the message warning us we don't have access to update the employee.

Note: Accessors require you to set the compiler to output ECMAScript 5 or higher.
A couple of things to note about accessors:

First, accessors require you to set the compiler to output ECMAScript 5 or higher.
Downlevelling to ECMAScript 3 is not supported.
Second, accessors with a `get` and no `set` are automatically inferred to be `readonly`.
This is helpful when generating a `.d.ts` file from your code, because users of your property can see that they can't change it.

# Static Properties

Expand Down
68 changes: 42 additions & 26 deletions pages/Compiler Options in MSBuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,68 @@ Compiler options can be specified using MSBuild properties within an MSBuild pro

Compiler Option | MSBuild Property Name | Allowed Values
---------------------------------------------|--------------------------------------------|-----------------
`--declaration` | TypeScriptGeneratesDeclarations | boolean
`--module` | TypeScriptModuleKind | `AMD`, `CommonJs`, `UMD`, or `System`
`--target` | TypeScriptTarget | `ES3`, `ES5`, or `ES6`
`--allowJs` | *Not supported in MSBuild* |
`--allowSyntheticDefaultImports` | TypeScriptAllowSyntheticDefaultImports | boolean
`--allowUnreachableCode` | TypeScriptAllowUnreachableCode | boolean
`--allowUnusedLabels` | TypeScriptAllowUnusedLabels | boolean
`--baseUrl` | TypeScriptBaseUrl | File path
`--charset` | TypeScriptCharset |
`--declaration` | TypeScriptGeneratesDeclarations | boolean
`--declarationDir` | TypeScriptDeclarationDir | File path
`--diagnostics` | *Not supported in MSBuild* |
`--emitBOM` | TypeScriptEmitBOM | boolean
`--emitDecoratorMetadata` | TypeScriptEmitDecoratorMetadata | boolean
`--experimentalAsyncFunctions` | TypeScriptExperimentalAsyncFunctions | boolean
`--experimentalDecorators` | TypeScriptExperimentalDecorators | boolean
`--forceConsistentCasingInFileNames` | TypeScriptForceConsistentCasingInFileNames | boolean
`--help` | *Not supported in MSBuild* |
`--inlineSourceMap` | TypeScriptInlineSourceMap | boolean
`--inlineSources` | TypeScriptInlineSources | boolean
`--init` | *Not supported in MSBuild* |
`--isolatedModules` | TypeScriptIsolatedModules | boolean
`--jsx` | TypeScriptJSXEmit | `React` or `Preserve`
`--lib` | TypeScriptLib | Comma-separated list of strings
`--listEmittedFiles` | *Not supported in MSBuild* |
`--listFiles` | *Not supported in MSBuild* |
`--locale` | *automatic* | Automatically set to PreferredUILang value
`--mapRoot` | TypeScriptMapRoot | File path
`--module` | TypeScriptModuleKind | `AMD`, `CommonJs`, `UMD`, `System` or `ES6`
`--moduleResolution` | TypeScriptModuleResolution | `Classic` or `Node`
`--newLine` | TypeScriptNewLine | `CRLF` or `LF`
`--noEmitOnError` | TypeScriptNoEmitOnError | boolean
`--noEmit` | *Not supported in MSBuild* |
`--noEmitHelpers` | TypeScriptNoEmitHelpers | boolean
`--noEmitOnError` | TypeScriptNoEmitOnError | boolean
`--noFallthroughCasesInSwitch` | TypeScriptNoFallthroughCasesInSwitch | boolean
`--noImplicitAny` | TypeScriptNoImplicitAny | boolean
`--noImplicitReturns` | TypeScriptNoImplicitReturns | boolean
`--noImplicitThis` | TypeScriptNoImplicitThis | boolean
`--noImplicitUseStrict` | TypeScriptNoImplicitUseStrict | boolean
`--noLib` | TypeScriptNoLib | boolean
`--noResolve` | TypeScriptNoResolve | boolean
`--out` | TypeScriptOutFile | File path
`--outDir` | TypeScriptOutDir | File path
`--outFile` | TypeScriptOutFile | File path
`--paths` | *Not supported in MSBuild* |
`--preserveConstEnums` | TypeScriptPreserveConstEnums | boolean
`--listEmittedFiles` | *Not supported in MSBuild* |
`--pretty` | *Not supported in MSBuild* |
`--reactNamespace` | TypeScriptReactNamespace | string
`--removeComments` | TypeScriptRemoveComments | boolean
`--rootDir` | TypeScriptRootDir | File path
`--isolatedModules` | TypeScriptIsolatedModules | boolean
`--rootDirs` | *Not supported in MSBuild* |
`--skipLibCheck` | TypeScriptSkipLibCheck | boolean
`--skipDefaultLibCheck` | TypeScriptSkipDefaultLibCheck | boolean
`--sourceMap` | TypeScriptSourceMap | File path
`--sourceRoot` | TypeScriptSourceRoot | File path
`--suppressImplicitAnyIndexErrors` | TypeScriptSuppressImplicitAnyIndexErrors | boolean
`--strictNullChecks` | TypeScriptStrictNullChecks | File path
`--suppressExcessPropertyErrors` | TypeScriptSuppressExcessPropertyErrors | boolean
`--moduleResolution` | TypeScriptModuleResolution | `Classic` or `Node`
`--experimentalAsyncFunctions` | TypeScriptExperimentalAsyncFunctions | boolean
`--jsx` | TypeScriptJSXEmit | `React` or `Preserve`
`--reactNamespace` | TypeScriptReactNamespace | string
`--skipDefaultLibCheck` | TypeScriptSkipDefaultLibCheck | boolean
`--allowUnusedLabels` | TypeScriptAllowUnusedLabels | boolean
`--noImplicitReturns` | TypeScriptNoImplicitReturns | boolean
`--noFallthroughCasesInSwitch` | TypeScriptNoFallthroughCasesInSwitch | boolean
`--allowUnreachableCode` | TypeScriptAllowUnreachableCode | boolean
`--forceConsistentCasingInFileNames` | TypeScriptForceConsistentCasingInFileNames | boolean
`--allowSyntheticDefaultImports` | TypeScriptAllowSyntheticDefaultImports | boolean
`--noImplicitUseStrict` | TypeScriptNoImplicitUseStrict | boolean
`--project` | *Not supported in VS* |
`--watch` | *Not supported in VS* |
`--diagnostics` | *Not supported in VS* |
`--listFiles` | *Not supported in VS* |
`--noEmit` | *Not supported in VS* |
`--allowJs` | *Not supported in VS* |
*VS only option* | TypeScriptAdditionalFlags | *Any compiler option*
`--suppressImplicitAnyIndexErrors` | TypeScriptSuppressImplicitAnyIndexErrors | boolean
`--target` | TypeScriptTarget | `ES3`, `ES5`, or `ES6`
`--traceResolution` | *Not supported in MSBuild* |
`--types` | *Not supported in MSBuild* |
`--typeRoots` | *Not supported in MSBuild* |
`--watch` | *Not supported in MSBuild* |
*MSBuild only option* | TypeScriptAdditionalFlags | *Any compiler option*

## What is supported in my version of Visual Studio?

Expand All @@ -86,4 +102,4 @@ Users using newer versions of TS, will see a prompt to upgrade their project on
## TypeScriptCompileBlocked

If you are using a different build tool to build your project (e.g. gulp, grunt , etc.) and VS for the development and debugging experience, set `<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>` in your project.
This should give you all the editing support, but not the build when you hit F5.
This should give you all the editing support, but not the build when you hit F5.
Loading