Skip to content

Commit 6829f2c

Browse files
committed
[docs] Readme simplify top example
1 parent 3ce0c97 commit 6829f2c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ with smart type inference.
1818
</p>
1919

2020
```ts
21-
import { match, P } from 'ts-pattern';
21+
import { match } from 'ts-pattern';
2222

2323
type Data =
2424
| { type: 'text'; content: string }
@@ -33,7 +33,7 @@ const result: Result = ...;
3333
return match(result)
3434
.with({ type: 'error' }, (res) => `<p>Oups! An error occured</p>`)
3535
.with({ type: 'ok', data: { type: 'text' } }, (res) => `<p>${res.data.content}</p>`)
36-
.with({ type: 'ok', data: { type: 'img', src: P.select() } }, (src) => `<img src=${src} />`)
36+
.with({ type: 'ok', data: { type: 'img' } }, (res) => `<img src=${res.data.src} />`)
3737
.exhaustive();
3838
```
3939

@@ -46,9 +46,9 @@ Write **better** and **safer conditions**. Pattern matching lets you express com
4646
- Works on **any data structure**: nested [Objects](#objects), [Arrays](#tuples-arrays), [Tuples](#tuples-arrays), [Sets](#sets), [Maps](#maps) and all primitive types.
4747
- **Typesafe**, with helpful [type inference](#type-inference).
4848
- **Exhaustiveness checking** support, enforcing that you are matching every possible case with [`.exhaustive()`](#exhaustive).
49-
- **Expressive API**, with catch-all and type specific **wildcards**: [`P._`](#P_-wildcard), [`P.string`](#pstring-wildcard), [`P.number`](#pnumber-wildcard), etc.
50-
- Supports [**predicates**](#Pwhen-patterns), [**unions**](#punion-patterns), [**intersections**](#pintersection-patterns) and [**exclusion**](#pnot-patterns) patterns for non-trivial cases.
51-
- Supports properties selection, via the [`P.select(name?)`](#pselect-patterns) function.
49+
- **Expressive API**, with catch-all and type specific **wildcards**: [`P._`](#P_-wildcard), [`P.string`](#Pstring-wildcard), [`P.number`](#Pnumber-wildcard), etc.
50+
- Supports [**predicates**](#Pwhen-patterns), [**unions**](#Punion-patterns), [**intersections**](#Pintersection-patterns) and [**exclusion**](#Pnot-patterns) patterns for non-trivial cases.
51+
- Supports properties selection, via the [`P.select(name?)`](#Pselect-patterns) function.
5252
- Tiny bundle footprint ([**only 1.6kB**](https://bundlephobia.com/package/ts-pattern)).
5353

5454
## What is Pattern Matching?

0 commit comments

Comments
 (0)