basarat / basarat/typescript-book

Another patch for Nominal Type

Open
#570 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
21.6k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

In [this article](https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing/), as a introduction to another thing, the author shows another kind of patch to use nominal types:

```ts
interface PersonIdBrand { _type: "Person"; }
type PersonId = PersonIdBrand & number;

interface BlogPostIdBrand { _type: "BlogPost"; }
type BlogPostId = number & BlogPostIdBrand;
```

It worked better for me with type inference than [your approach with enums](https://basarat.gitbook.io/typescript/main-1/nominaltyping#using-enums).

Do you think that is a good idea to add this alternative? or is there a well known issue with this approach?

Contributor guide

Open the contributing guide

Research direction

Compare the alternative nominal-typing pattern in the linked Atomic Object article with the existing enum approach in the book's nominal typing section. Check its type-inference behavior and any documented limitations before deciding whether it belongs. Done means reaching a clear inclusion decision and defining the explanation and examples needed if it is added.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.