type-fest 3.11.0 → 3.12.0
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/index.d.ts +1 -0
- package/package.json +1 -1
- package/readme.md +1 -0
- package/source/package-json.d.ts +3 -17
- package/source/set-readonly.d.ts +38 -0
- package/source/set-required.d.ts +11 -5
package/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export type {Promisable} from './source/promisable';
|
|
|
33
33
|
export type {Opaque, UnwrapOpaque} from './source/opaque';
|
|
34
34
|
export type {InvariantOf} from './source/invariant-of';
|
|
35
35
|
export type {SetOptional} from './source/set-optional';
|
|
36
|
+
export type {SetReadonly} from './source/set-readonly';
|
|
36
37
|
export type {SetRequired} from './source/set-required';
|
|
37
38
|
export type {SetNonNullable} from './source/set-non-nullable';
|
|
38
39
|
export type {ValueOf} from './source/value-of';
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -119,6 +119,7 @@ Click the type names for complete docs.
|
|
|
119
119
|
- [`UnwrapOpaque`](source/opaque.d.ts) - Revert an [opaque type](https://codemix.com/opaque-types-in-javascript/) back to its original type.
|
|
120
120
|
- [`InvariantOf`](source/invariant-of.d.ts) - Create an [invariant type](https://basarat.gitbook.io/typescript/type-system/type-compatibility#footnote-invariance), which is a type that does not accept supertypes and subtypes.
|
|
121
121
|
- [`SetOptional`](source/set-optional.d.ts) - Create a type that makes the given keys optional.
|
|
122
|
+
- [`SetReadonly`](source/set-readonly.d.ts) - Create a type that makes the given keys readonly.
|
|
122
123
|
- [`SetRequired`](source/set-required.d.ts) - Create a type that makes the given keys required.
|
|
123
124
|
- [`SetNonNullable`](source/set-non-nullable.d.ts) - Create a type that makes the given keys non-nullable.
|
|
124
125
|
- [`ValueOf`](source/value-of.d.ts) - Create a union of the given object's values, and optionally specify which keys to get the values from.
|
package/source/package-json.d.ts
CHANGED
|
@@ -208,26 +208,12 @@ declare namespace PackageJson {
|
|
|
208
208
|
*/
|
|
209
209
|
export type Dependency = Partial<Record<string, string>>;
|
|
210
210
|
|
|
211
|
-
/**
|
|
212
|
-
Conditions which provide a way to resolve a package entry point based on the environment.
|
|
213
|
-
*/
|
|
214
|
-
export type ExportCondition = LiteralUnion<
|
|
215
|
-
| 'import'
|
|
216
|
-
| 'require'
|
|
217
|
-
| 'node'
|
|
218
|
-
| 'node-addons'
|
|
219
|
-
| 'deno'
|
|
220
|
-
| 'browser'
|
|
221
|
-
| 'electron'
|
|
222
|
-
| 'react-native'
|
|
223
|
-
| 'default',
|
|
224
|
-
string
|
|
225
|
-
>;
|
|
226
|
-
|
|
227
211
|
/**
|
|
228
212
|
A mapping of conditions and the paths to which they resolve.
|
|
229
213
|
*/
|
|
230
|
-
type ExportConditions = {
|
|
214
|
+
type ExportConditions = { // eslint-disable-line @typescript-eslint/consistent-indexed-object-style
|
|
215
|
+
[condition: string]: Exports;
|
|
216
|
+
};
|
|
231
217
|
|
|
232
218
|
/**
|
|
233
219
|
Entry points of a module, optionally with conditions and subpath exports.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type {Except} from './except';
|
|
2
|
+
import type {Simplify} from './simplify';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
Create a type that makes the given keys readonly. The remaining keys are kept as is.
|
|
6
|
+
|
|
7
|
+
Use-case: You want to define a single model where the only thing that changes is whether or not some of the keys are readonly.
|
|
8
|
+
|
|
9
|
+
@example
|
|
10
|
+
```
|
|
11
|
+
import type {SetReadonly} from 'type-fest';
|
|
12
|
+
|
|
13
|
+
type Foo = {
|
|
14
|
+
a: number;
|
|
15
|
+
readonly b: string;
|
|
16
|
+
c: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type SomeReadonly = SetReadonly<Foo, 'b' | 'c'>;
|
|
20
|
+
// type SomeReadonly = {
|
|
21
|
+
// a: number;
|
|
22
|
+
// readonly b: string; // Was already readonly and still is.
|
|
23
|
+
// readonly c: boolean; // Is now readonly.
|
|
24
|
+
// }
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
@category Object
|
|
28
|
+
*/
|
|
29
|
+
export type SetReadonly<BaseType, Keys extends keyof BaseType> =
|
|
30
|
+
// `extends unknown` is always going to be the case and is used to convert any
|
|
31
|
+
// union into a [distributive conditional
|
|
32
|
+
// type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
33
|
+
BaseType extends unknown
|
|
34
|
+
? Simplify<
|
|
35
|
+
Except<BaseType, Keys> &
|
|
36
|
+
Readonly<Pick<BaseType, Keys>>
|
|
37
|
+
>
|
|
38
|
+
: never;
|
package/source/set-required.d.ts
CHANGED
|
@@ -27,8 +27,14 @@ type SomeRequired = SetRequired<Foo, 'b' | 'c'>;
|
|
|
27
27
|
@category Object
|
|
28
28
|
*/
|
|
29
29
|
export type SetRequired<BaseType, Keys extends keyof BaseType> =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
// `extends unknown` is always going to be the case and is used to convert any
|
|
31
|
+
// union into a [distributive conditional
|
|
32
|
+
// type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
33
|
+
BaseType extends unknown
|
|
34
|
+
? Simplify<
|
|
35
|
+
// Pick just the keys that are optional from the base type.
|
|
36
|
+
Except<BaseType, Keys> &
|
|
37
|
+
// Pick the keys that should be required from the base type and make them required.
|
|
38
|
+
Required<Pick<BaseType, Keys>>
|
|
39
|
+
>
|
|
40
|
+
: never;
|