Skip to content

Commit 879d8ae

Browse files
authored
PickIndexSignature/OmitIndexSignature: Clean up JSDoc comments (#1039)
1 parent 979eccf commit 879d8ae

File tree

2 files changed

+0
-64
lines changed

2 files changed

+0
-64
lines changed

source/omit-index-signature.d.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,6 @@ type OmitIndexSignature<ObjectType> = {
6161
6262
If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
6363
64-
```
65-
import type {OmitIndexSignature} from 'type-fest';
66-
67-
type OmitIndexSignature<ObjectType> = {
68-
[KeyType in keyof ObjectType
69-
as {} extends Record<KeyType, unknown>
70-
? never // => Remove this `KeyType`.
71-
: KeyType // => Keep this `KeyType` as it is.
72-
]: ObjectType[KeyType];
73-
};
74-
```
75-
7664
@example
7765
```
7866
import type {OmitIndexSignature} from 'type-fest';

source/pick-index-signature.d.ts

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ Pick only index signatures from the given object type, leaving out all explicitl
33
44
This is the counterpart of `OmitIndexSignature`.
55
6-
When you use a type that will iterate through an object that has indexed keys and explicitly defined keys you end up with a type where only the indexed keys are kept. This is because `keyof` of an indexed type always returns `string | number | symbol`, because every key is possible in that object. With this type, you can save the indexed keys and reinject them later, like in the second example below.
7-
86
@example
97
```
108
import type {PickIndexSignature} from 'type-fest';
@@ -42,56 +40,6 @@ type ExampleIndexSignature = PickIndexSignature<Example>;
4240
// }
4341
```
4442
45-
@example
46-
```
47-
import type {OmitIndexSignature, PickIndexSignature, Simplify} from 'type-fest';
48-
49-
type Foo = {
50-
[x: string]: string;
51-
foo: string;
52-
bar: number;
53-
};
54-
55-
// Imagine that you want a new type `Bar` that comes from `Foo`.
56-
// => {
57-
// [x: string]: string;
58-
// bar: number;
59-
// };
60-
61-
type Bar = Omit<Foo, 'foo'>;
62-
// This is not working because `Omit` returns only indexed keys.
63-
// => {
64-
// [x: string]: string;
65-
// [x: number]: string;
66-
// }
67-
68-
// One solution is to save the indexed signatures to new type.
69-
type FooIndexSignature = PickIndexSignature<Foo>;
70-
// => {
71-
// [x: string]: string;
72-
// }
73-
74-
// Get a new type without index signatures.
75-
type FooWithoutIndexSignature = OmitIndexSignature<Foo>;
76-
// => {
77-
// foo: string;
78-
// bar: number;
79-
// }
80-
81-
// At this point we can use Omit to get our new type.
82-
type BarWithoutIndexSignature = Omit<FooWithoutIndexSignature, 'foo'>;
83-
// => {
84-
// bar: number;
85-
// }
86-
87-
// And finally we can merge back the indexed signatures.
88-
type BarWithIndexSignature = Simplify<BarWithoutIndexSignature & FooIndexSignature>;
89-
// => {
90-
// [x: string]: string;
91-
// bar: number;
92-
// }
93-
```
94-
9543
@see OmitIndexSignature
9644
@category Object
9745
*/

0 commit comments

Comments
 (0)