type-fest 0.5.2 → 0.6.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 +2 -1
- package/package.json +6 -5
- package/readme.md +4 -3
- package/source/basic.d.ts +3 -0
- package/source/except.d.ts +22 -0
- package/source/merge.d.ts +2 -2
- package/source/package-json.d.ts +7 -0
- package/source/promisable.d.ts +23 -0
- package/source/require-at-least-one.d.ts +2 -2
- package/source/omit.d.ts +0 -17
package/index.d.ts
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
export * from './source/basic';
|
|
3
3
|
|
|
4
4
|
// Utilities
|
|
5
|
-
export {
|
|
5
|
+
export {Except} from './source/except';
|
|
6
6
|
export {Mutable} from './source/mutable';
|
|
7
7
|
export {Merge} from './source/merge';
|
|
8
8
|
export {MergeExclusive} from './source/merge-exclusive';
|
|
9
9
|
export {RequireAtLeastOne} from './source/require-at-least-one';
|
|
10
10
|
export {ReadonlyDeep} from './source/readonly-deep';
|
|
11
11
|
export {LiteralUnion} from './source/literal-union';
|
|
12
|
+
export {Promisable} from './source/promisable';
|
|
12
13
|
|
|
13
14
|
// Miscellaneous
|
|
14
15
|
export {PackageJson} from './source/package-json';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-fest",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "A collection of essential TypeScript types",
|
|
5
5
|
"license": "(MIT OR CC0-1.0)",
|
|
6
6
|
"repository": "sindresorhus/type-fest",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"url": "sindresorhus.com"
|
|
11
11
|
},
|
|
12
12
|
"engines": {
|
|
13
|
-
"node": ">=
|
|
13
|
+
"node": ">=8"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"test": "xo && tsd"
|
|
@@ -31,9 +31,10 @@
|
|
|
31
31
|
"json"
|
|
32
32
|
],
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@sindresorhus/tsconfig": "^0.
|
|
35
|
-
"@typescript-eslint/eslint-plugin": "^1.
|
|
36
|
-
"eslint
|
|
34
|
+
"@sindresorhus/tsconfig": "^0.4.0",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^1.9.0",
|
|
36
|
+
"@typescript-eslint/parser": "^1.10.2",
|
|
37
|
+
"eslint-config-xo-typescript": "^0.14.0",
|
|
37
38
|
"tsd": "^0.7.3",
|
|
38
39
|
"xo": "^0.24.0"
|
|
39
40
|
},
|
package/readme.md
CHANGED
|
@@ -36,14 +36,14 @@ $ npm install type-fest
|
|
|
36
36
|
## Usage
|
|
37
37
|
|
|
38
38
|
```ts
|
|
39
|
-
import {
|
|
39
|
+
import {Except} from 'type-fest';
|
|
40
40
|
|
|
41
41
|
type Foo = {
|
|
42
42
|
unicorn: string;
|
|
43
43
|
rainbow: boolean;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
type FooWithoutRainbow =
|
|
46
|
+
type FooWithoutRainbow = Except<Foo, 'rainbow'>;
|
|
47
47
|
//=> {unicorn: string}
|
|
48
48
|
```
|
|
49
49
|
|
|
@@ -64,13 +64,14 @@ Click the type names for complete docs.
|
|
|
64
64
|
|
|
65
65
|
### Utilities
|
|
66
66
|
|
|
67
|
-
- [`
|
|
67
|
+
- [`Except`](source/except.d.ts) - Create a type from an object type without certain keys. This is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type).
|
|
68
68
|
- [`Mutable`](source/mutable.d.ts) - Convert an object with `readonly` properties into a mutable object. Inverse of `Readonly<T>`.
|
|
69
69
|
- [`Merge`](source/merge.d.ts) - Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
70
70
|
- [`MergeExclusive`](source/merge-exclusive.d.ts) - Create a type that has mutually exclusive properties.
|
|
71
71
|
- [`RequireAtLeastOne`](source/require-at-least-one.d.ts) - Create a type that requires at least one of the given properties.
|
|
72
72
|
- [`ReadonlyDeep`](source/readonly-deep.d.ts) - Create a deeply immutable version of a `object`/`Map`/`Set`/`Array` type.
|
|
73
73
|
- [`LiteralUnion`](source/literal-union.d.ts) - Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union. Workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729).
|
|
74
|
+
- [`Promisable`](source/promisable.d.ts) - Create a type that represents either the value or the value wrapped in `PromiseLike`.
|
|
74
75
|
|
|
75
76
|
### Miscellaneous
|
|
76
77
|
|
package/source/basic.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export type Primitive =
|
|
|
13
13
|
| symbol
|
|
14
14
|
| bigint;
|
|
15
15
|
|
|
16
|
+
// TODO: Remove the `= unknown` sometime in the future when most users are on TS 3.5 as it's now the default
|
|
16
17
|
/**
|
|
17
18
|
Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
|
18
19
|
*/
|
|
@@ -36,6 +37,8 @@ export type TypedArray =
|
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
39
|
Matches a JSON object.
|
|
40
|
+
|
|
41
|
+
This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`.
|
|
39
42
|
*/
|
|
40
43
|
export type JsonObject = {[key: string]: JsonValue};
|
|
41
44
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Create a type from an object type without certain keys.
|
|
3
|
+
|
|
4
|
+
This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
|
|
5
|
+
|
|
6
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/30825) if you want to have the stricter version as a built-in in TypeScript.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import {Except} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type Foo = {
|
|
13
|
+
a: number;
|
|
14
|
+
b: string;
|
|
15
|
+
c: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type FooWithoutA = Except<Foo, 'a' | 'c'>;
|
|
19
|
+
//=> {b: string};
|
|
20
|
+
```
|
|
21
|
+
*/
|
|
22
|
+
export type Except<ObjectType, KeysType extends keyof ObjectType> = Pick<ObjectType, Exclude<keyof ObjectType, KeysType>>;
|
package/source/merge.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {Except} from './except';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
@@ -19,4 +19,4 @@ type Bar = {
|
|
|
19
19
|
const ab: Merge<Foo, Bar> = {a: 1, b: 2};
|
|
20
20
|
```
|
|
21
21
|
*/
|
|
22
|
-
export type Merge<FirstType, SecondType> =
|
|
22
|
+
export type Merge<FirstType, SecondType> = Except<FirstType, Extract<keyof FirstType, keyof SecondType>> & SecondType;
|
package/source/package-json.d.ts
CHANGED
|
@@ -251,6 +251,13 @@ declare namespace PackageJson {
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
export interface YarnConfiguration {
|
|
254
|
+
/**
|
|
255
|
+
If your package only allows one version of a given dependency, and you’d like to enforce the same behavior as `yarn install --flat` on the command line, set this to `true`.
|
|
256
|
+
|
|
257
|
+
Note that if your `package.json` contains `"flat": true` and other packages depend on yours (e.g. you are building a library rather than an application), those other packages will also need `"flat": true` in their `package.json` or be installed with `yarn install --flat` on the command-line.
|
|
258
|
+
*/
|
|
259
|
+
flat?: boolean;
|
|
260
|
+
|
|
254
261
|
/**
|
|
255
262
|
Selective version resolutions. Allows the definition of custom package versions inside dependencies without manual edits in the `yarn.lock` file.
|
|
256
263
|
*/
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Create a type that represents either the value or the value wrapped in `PromiseLike`.
|
|
3
|
+
|
|
4
|
+
Use-cases:
|
|
5
|
+
- A function accepts a callback that may either return a value synchronously or may return a promised value.
|
|
6
|
+
- This type could be the return type of `Promise#then()`, `Promise#catch()`, and `Promise#finally()` callbacks.
|
|
7
|
+
|
|
8
|
+
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31394) if you want to have this type as a built-in in TypeScript.
|
|
9
|
+
|
|
10
|
+
@example
|
|
11
|
+
```
|
|
12
|
+
import {Promisable} from 'type-fest';
|
|
13
|
+
|
|
14
|
+
async function logger(getLogEntry: () => Promisable<string>): Promise<void> {
|
|
15
|
+
const entry = await getLogEntry();
|
|
16
|
+
console.log(entry);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
logger(() => 'foo');
|
|
20
|
+
logger(() => Promise.resolve('bar'));
|
|
21
|
+
```
|
|
22
|
+
*/
|
|
23
|
+
export type Promisable<T> = T | PromiseLike<T>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {Except} from './except';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
Create a type that requires at least one of the given properties. The remaining properties are kept as is.
|
|
@@ -29,4 +29,4 @@ export type RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType = ke
|
|
|
29
29
|
)
|
|
30
30
|
}[KeysType]
|
|
31
31
|
// …then, make intersection types by adding the remaining properties to each mapped type.
|
|
32
|
-
&
|
|
32
|
+
& Except<ObjectType, KeysType>;
|
package/source/omit.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
Create a type from an object type without certain keys.
|
|
3
|
-
|
|
4
|
-
@example
|
|
5
|
-
```
|
|
6
|
-
import {Omit} from 'type-fest';
|
|
7
|
-
|
|
8
|
-
type Foo = {
|
|
9
|
-
a: number;
|
|
10
|
-
b: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
type FooWithoutA = Omit<Foo, 'a'>;
|
|
14
|
-
//=> {b: string};
|
|
15
|
-
```
|
|
16
|
-
*/
|
|
17
|
-
export type Omit<ObjectType, KeysType extends keyof ObjectType> = Pick<ObjectType, Exclude<keyof ObjectType, KeysType>>;
|