Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would get rid of 'actually' and 'extremely' since they just add noise.


```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
2 changes: 1 addition & 1 deletion pages/Compiler Options in MSBuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Compiler Option | MSBuild Property Name
`--suppressImplicitAnyIndexErrors` | TypeScriptSuppressImplicitAnyIndexErrors | boolean
`--target` | TypeScriptTarget | `ES3`, `ES5`, or `ES6`
`--traceResolution` | *Not supported in MSBuild* |
`--types` | *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*
Expand Down