basarat / basarat/typescript-book

Subtraction Types

Open
#399 1 comment 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

Using a clever combination of `Pick` to create an `Omit`: (Source: https://github.com/Microsoft/TypeScript/issues/19569)

```
export type Diff = ({[P in T]: P} &
{[P in U]: never} & {[x: string]: never})[T]
export type Omit = Pick>
```

Better with conditional types : https://github.com/Microsoft/TypeScript/issues/19569#issuecomment-359471618

```
export type Diff = T extends U ? never : T; // Remove types from T that are assignable to U
export type Omit = Pick>
```

Contributor guide

Open the contributing guide

Research direction

Review the TypeScript book’s existing coverage of Pick, Omit, and conditional types, then compare it with the two Diff/Omit examples and the linked TypeScript discussion. Done should be a clearly scoped decision about whether and where this material belongs, with the relevant explanation and examples updated if accepted.

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.