Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Readme.md #5

Open
wants to merge 2 commits 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: 6 additions & 6 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ minutesToSeconds(seconds)
```

Nominal types solve this problem

```ts
import { Nominal, nominal } from 'nominal-types';
import { Nominal } from 'nominal-types';

type Minutes = Nominal<'Minutes', number>;
type Seconds = Nominal<'Seconds', number>;

const minutesToSeconds = (minutes: Minutes) => minutes * 60

// You can directly type cast or use nominal.make
const seconds = nominal.make<Seconds>(420)
const seconds = 420 as Seconds
const minutes = 1337 as Minutes

// doesn't work, yay type safety
Expand Down Expand Up @@ -108,9 +108,9 @@ binarySearch(nonEmpty(sort(regularArray)))
More examples in [examples folder](./examples), you can also see them typed on replit.

| Example | Link |
|-------------|-----------------------------------------------------------|
| basic | https://replit.com/@CryogenicPlanet/Nominal#basic.ts |
| sorting | https://replit.com/@CryogenicPlanet/Nominal#sort.ts |
| ----------- | --------------------------------------------------------- |
| basic | https://replit.com/@CryogenicPlanet/Nominal#basic.ts |
| sorting | https://replit.com/@CryogenicPlanet/Nominal#sort.ts |
| composing | https://replit.com/@CryogenicPlanet/Nominal#composing.ts |
| safeRecords | https://replit.com/@CryogenicPlanet/Nominal#safeRecord.ts |

Expand Down