ts-gems 4.0.1 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/api/omit.md +6 -5
- package/docs/api/pick.md +6 -4
- package/docs/api.md +3 -3
- package/lib/omit.d.ts +1 -10
- package/lib/pick.d.ts +1 -10
- package/package.json +1 -1
package/docs/api/omit.md
CHANGED
|
@@ -9,10 +9,11 @@ convention](../api.md#the-deep--deeper-convention) for `DeepOmitTypes`/
|
|
|
9
9
|
|
|
10
10
|
## `StrictOmit<T, X>`
|
|
11
11
|
|
|
12
|
-
Like the built-in `Omit<T, K>`, but
|
|
13
|
-
|
|
14
|
-
[`StrictPick`](pick.md#strictpickt-x),
|
|
15
|
-
|
|
12
|
+
Like the built-in `Omit<T, K>`, but `X` is constrained to `keyof T`, so a
|
|
13
|
+
typo in the key you're omitting is a compile error instead of a silent
|
|
14
|
+
no-op. Unlike [`StrictPick`](pick.md#strictpickt-x), it does **not** also
|
|
15
|
+
drop `never`-typed keys — only the key(s) named in `X` are removed, by
|
|
16
|
+
identity, regardless of their value type.
|
|
16
17
|
|
|
17
18
|
```ts
|
|
18
19
|
import type { StrictOmit } from 'ts-gems';
|
|
@@ -24,7 +25,7 @@ interface Row {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
type Result = StrictOmit<Row, 'b'>;
|
|
27
|
-
// { a?: number } - `
|
|
28
|
+
// { a?: number; c: never } - only `b` is removed
|
|
28
29
|
```
|
|
29
30
|
|
|
30
31
|
## `OmitFunctions<T>`
|
package/docs/api/pick.md
CHANGED
|
@@ -7,9 +7,11 @@ See [Omit](omit.md) for the inverse operations.
|
|
|
7
7
|
|
|
8
8
|
## `StrictPick<T, X>`
|
|
9
9
|
|
|
10
|
-
Like the built-in `Pick<T, K>`, but
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
Like the built-in `Pick<T, K>`, but `X` is constrained to `keyof T`, so a
|
|
11
|
+
typo in the key you're picking is a compile error instead of silently
|
|
12
|
+
producing `never`. It only selects by key identity — it does **not** also
|
|
13
|
+
drop `never`-typed keys, so it stays correct when `T` is still an open
|
|
14
|
+
generic type parameter (e.g. used inside another generic function).
|
|
13
15
|
|
|
14
16
|
```ts
|
|
15
17
|
import type { StrictPick } from 'ts-gems';
|
|
@@ -21,7 +23,7 @@ interface Row {
|
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
type Result = StrictPick<Row, 'a' | 'c'>;
|
|
24
|
-
// { a?: number } -
|
|
26
|
+
// { a?: number; c: never } - both named keys are kept
|
|
25
27
|
```
|
|
26
28
|
|
|
27
29
|
## `PickFunctions<T>`
|
package/docs/api.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
docs-baseline
|
|
3
|
-
git-commit:
|
|
4
|
-
package-version: 4.0.
|
|
3
|
+
git-commit: 27bbe999f45fa24fe4e1d7d32d5639defa285bdc
|
|
4
|
+
package-version: 4.0.1
|
|
5
5
|
date: 2026-09-09
|
|
6
6
|
verified-against: lib/
|
|
7
|
-
diff-command: git diff
|
|
7
|
+
diff-command: git diff 27bbe999f45fa24fe4e1d7d32d5639defa285bdc..HEAD -- lib/
|
|
8
8
|
-->
|
|
9
9
|
|
|
10
10
|
<p align="center">
|
package/lib/omit.d.ts
CHANGED
|
@@ -7,16 +7,7 @@ import { IfFunction, IfNever, IfTuple } from './type-check.js';
|
|
|
7
7
|
* while preserving strict type checking.
|
|
8
8
|
*/
|
|
9
9
|
export type StrictOmit<T, X extends keyof T> = {
|
|
10
|
-
[
|
|
11
|
-
K in keyof T as Or<
|
|
12
|
-
// Omit never keys
|
|
13
|
-
IfNever<Exclude<T[K], undefined>>,
|
|
14
|
-
// Omit X
|
|
15
|
-
K extends X ? true : false
|
|
16
|
-
> extends true
|
|
17
|
-
? never
|
|
18
|
-
: K
|
|
19
|
-
]: T[K];
|
|
10
|
+
[K in keyof T as K extends X ? never : K]: T[K];
|
|
20
11
|
};
|
|
21
12
|
|
|
22
13
|
/**
|
package/lib/pick.d.ts
CHANGED
|
@@ -13,16 +13,7 @@ import {
|
|
|
13
13
|
* while preserving strict type checking.
|
|
14
14
|
*/
|
|
15
15
|
export type StrictPick<T, X extends keyof T> = {
|
|
16
|
-
[
|
|
17
|
-
K in keyof T as Or<
|
|
18
|
-
// Omit never keys
|
|
19
|
-
IfNever<Exclude<T[K], undefined>>,
|
|
20
|
-
// Omit X
|
|
21
|
-
K extends X ? false : true
|
|
22
|
-
> extends true
|
|
23
|
-
? never
|
|
24
|
-
: K
|
|
25
|
-
]: T[K];
|
|
16
|
+
[K in keyof T as K extends X ? K : never]: T[K];
|
|
26
17
|
};
|
|
27
18
|
|
|
28
19
|
/**
|