Skip to content

Commit

Permalink
docs: readme has a section on constant type inference
Browse files Browse the repository at this point in the history
  • Loading branch information
barona-mika-vilpas committed Dec 27, 2023
1 parent b3e0abb commit 75aee24
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,21 @@ string("ice").pipe(
);
```

#### Constant type inference

If you're using TypeScript, you may want to keep using `string("world")` instead of `"world"`. This is because the former will infer the type of the parser to be `Parjser<"world">`, while the latter will infer it to be `Parjser<string>`.

Here's an example of the difference:

```typescript
// This will infer "world" to the constant type of "world"
const parser: Parjser<["hello", "world"]> = string("hello").pipe(then(string("world")));

// This will infer to the string type, which may be more confusing to debug, and
// have issues with type aliases
const parser: Parjser<["hello", string]> = string("hello").pipe(then("world"));
```

### Debugging

> 🆕 new in version `1.0.0`
Expand Down

0 comments on commit 75aee24

Please sign in to comment.