Skip to content

Commit 34a369a

Browse files
docs: ✏️ move examples from the README to JSDoc
1 parent 2be9053 commit 34a369a

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

packages/immutable/README.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,6 @@ Generic type for deeply immutable data.
1212
yarn add @pacote/immutable
1313
```
1414

15-
## Usage
16-
17-
```typescript
18-
import type { Immutable } from '@pacote/immutable'
19-
20-
type Foo = { foo: string }
21-
22-
const mutable: Foo[] = [{ foo: 'bar' }]
23-
24-
// Allowed:
25-
mutable.push({ foo: 'baz' })
26-
mutable[0].foo = 'baz'
27-
delete mutable[0].foo
28-
29-
const immutable: Immutable<Foo[]> = [{ foo: 'bar' }]
30-
31-
// Not allowed:
32-
immutable.push({ foo: 'baz' })
33-
immutable[0].foo = 'baz'
34-
delete immutable[0].foo
35-
```
36-
3715
## License
3816

3917
MIT © [Luís Rodrigues](https://goblindegook.com).

packages/immutable/src/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
/**
2+
* Generic type that converts deeply nested structures into immutable variants.
3+
*
4+
* Useful when you want to treat mutable shapes such as arrays, maps, sets, and
5+
* plain objects as readonly data structures throughout your application.
6+
*
7+
* @example
8+
* import type { Immutable } from '@pacote/immutable'
9+
*
10+
* type Foo = { foo: string }
11+
*
12+
* const mutable: Foo[] = [{ foo: 'bar' }]
13+
*
14+
* // Allowed:
15+
* mutable.push({ foo: 'baz' })
16+
* mutable[0].foo = 'baz'
17+
* delete mutable[0].foo
18+
*
19+
* const immutable: Immutable<Foo[]> = [{ foo: 'bar' }]
20+
*
21+
* // Not allowed:
22+
* immutable.push({ foo: 'baz' })
23+
* immutable[0].foo = 'baz'
24+
* delete immutable[0].foo
25+
*/
126
export type Immutable<T> = T extends readonly [infer First, ...infer Rest]
227
? readonly [Immutable<First>, ...ImmutableTuple<Rest>]
328
: T extends readonly (infer E)[]

0 commit comments

Comments
 (0)