Skip to content

Commit

Permalink
Added a mention of the Promise type helper (#2931)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpocock authored Sep 1, 2023
1 parent 3b191d1 commit 087d11b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/documentation/copy/en/handbook-v2/Everyday Types.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ We'll learn more about the syntax `T<U>` when we cover _generics_.

> Note that `[number]` is a different thing; refer to the section on [Tuples](/docs/handbook/2/objects.html#tuple-types).

## `any`

TypeScript also has a special type, `any`, that you can use whenever you don't want a particular value to cause typechecking errors.
Expand All @@ -44,7 +43,7 @@ When a value is of type `any`, you can access any properties of it (which will i
```ts twoslash
let obj: any = { x: 0 };
// None of the following lines of code will throw compiler errors.
// Using `any` disables all further type checking, and it is assumed
// Using `any` disables all further type checking, and it is assumed
// you know the environment better than TypeScript.
obj.foo();
obj();
Expand Down Expand Up @@ -132,6 +131,16 @@ Much like variable type annotations, you usually don't need a return type annota
The type annotation in the above example doesn't change anything.
Some codebases will explicitly specify a return type for documentation purposes, to prevent accidental changes, or just for personal preference.

#### Functions Which Return Promises

If you want to annotate the return type of a function which returns a promise, you should use the `Promise` type:

```ts twoslash
async function getFavoriteNumber(): Promise<number> {
return 26;
}
```

### Anonymous Functions

Anonymous functions are a little bit different from function declarations.
Expand Down Expand Up @@ -501,7 +510,7 @@ If this happens, you can use two assertions, first to `any` (or `unknown`, which
declare const expr: any;
type T = { a: 1; b: 2; c: 3 };
// ---cut---
const a = (expr as any) as T;
const a = expr as any as T;
```

## Literal Types
Expand Down

0 comments on commit 087d11b

Please sign in to comment.