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

Commit 64c3564

Browse files
Merge pull request #314 from Microsoft/nullUndefined
Null and Undefined
2 parents c3b45c7 + 0779597 commit 64c3564

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pages/Basic Types.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,27 @@ Declaring variables of type `void` is not useful because you can only assign `un
190190
let unusable: void = undefined;
191191
```
192192

193+
# Null and Undefined
194+
195+
In TypeScript, both `undefined` and `null` actually have their own types named `undefined` and `null` respectively.
196+
Much like `void`, they're not extremely useful on their own:
197+
198+
```ts
199+
// Not much else we can assign to these variables!
200+
let u: undefined = undefined;
201+
let n: null = null;
202+
```
203+
204+
By default `null` and `undefined` are subtypes of all other types.
205+
That means you can assign `null` and `undefined` to something like `number`.
206+
207+
However, when using the `--strictNullChecks` flag, `null` and `undefined` are only assignable to `void` and their respective types.
208+
This helps avoid *many* common errors.
209+
In cases where you want to pass in either a `string` or `null` or `undefined`, you can use the union type `string | null | undefined`.
210+
Once again, more on union types later on.
211+
212+
> 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.
213+
193214
# Type assertions
194215

195216
Sometimes you'll end up in a situation where you'll know more about a value than TypeScript does.

pages/Compiler Options in MSBuild.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Compiler Option | MSBuild Property Name
8080
`--suppressImplicitAnyIndexErrors` | TypeScriptSuppressImplicitAnyIndexErrors | boolean
8181
`--target` | TypeScriptTarget | `ES3`, `ES5`, or `ES6`
8282
`--traceResolution` | *Not supported in MSBuild* |
83-
`--types` | *Not supported in MSBuild* |
83+
`--types` | *Not supported in MSBuild* |
8484
`--typeRoots` | *Not supported in MSBuild* |
8585
`--watch` | *Not supported in MSBuild* |
8686
*MSBuild only option* | TypeScriptAdditionalFlags | *Any compiler option*

0 commit comments

Comments
 (0)