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

Update Basic Types.md #971

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 3 additions & 9 deletions pages/Basic Types.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,12 @@ console.log(x[0].substr(1)); // OK
console.log(x[1].substr(1)); // Error, 'number' does not have 'substr'
```

When accessing an element outside the set of known indices, a union type is used instead:
When accessing an element outside the set of known indices, an error will occur:

```ts
x[3] = "world"; // OK, 'string' can be assigned to 'string | number'

console.log(x[5].toString()); // OK, 'string' and 'number' both have 'toString'

x[6] = true; // Error, 'boolean' isn't 'string | number'
x[3] = "world"; // Error, Tuple type '[string, number]' of length '2' has no element at index '3'
```

Union types are an advanced topic that we'll cover in a later chapter.

# [Enum](Enum)

A helpful addition to the standard set of datatypes from JavaScript is the `enum`.
Expand Down Expand Up @@ -207,7 +201,7 @@ 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.
Union types are an advanced topic that we'll cover in a later chapter.

> 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.

Expand Down