type-fest 4.39.1 → 4.40.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 +3 -0
- package/package.json +3 -3
- package/readme.md +3 -10
- package/source/is-float.d.ts +24 -14
- package/source/is-integer.d.ts +24 -14
- package/source/non-empty-string.d.ts +28 -0
- package/source/unknown-map.d.ts +24 -0
- package/source/unknown-set.d.ts +24 -0
package/index.d.ts
CHANGED
|
@@ -11,8 +11,11 @@ export type {DistributedPick} from './source/distributed-pick';
|
|
|
11
11
|
export type {EmptyObject, IsEmptyObject} from './source/empty-object';
|
|
12
12
|
export type {IfEmptyObject} from './source/if-empty-object';
|
|
13
13
|
export type {NonEmptyObject} from './source/non-empty-object';
|
|
14
|
+
export type {NonEmptyString} from './source/non-empty-string';
|
|
14
15
|
export type {UnknownRecord} from './source/unknown-record';
|
|
15
16
|
export type {UnknownArray} from './source/unknown-array';
|
|
17
|
+
export type {UnknownSet} from './source/unknown-set';
|
|
18
|
+
export type {UnknownMap} from './source/unknown-map';
|
|
16
19
|
export type {Except} from './source/except';
|
|
17
20
|
export type {TaggedUnion} from './source/tagged-union';
|
|
18
21
|
export type {Writable} from './source/writable';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-fest",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.40.0",
|
|
4
4
|
"description": "A collection of essential TypeScript types",
|
|
5
5
|
"license": "(MIT OR CC0-1.0)",
|
|
6
6
|
"repository": "sindresorhus/type-fest",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"expect-type": "^1.1.0",
|
|
45
45
|
"npm-run-all2": "^7.0.1",
|
|
46
|
-
"tsd": "^0.
|
|
47
|
-
"typescript": "~5.8.
|
|
46
|
+
"tsd": "^0.32.0",
|
|
47
|
+
"typescript": "~5.8.3",
|
|
48
48
|
"xo": "^0.60.0"
|
|
49
49
|
},
|
|
50
50
|
"xo": {
|
package/readme.md
CHANGED
|
@@ -33,16 +33,6 @@
|
|
|
33
33
|
</a>
|
|
34
34
|
<br>
|
|
35
35
|
<br>
|
|
36
|
-
<a href="https://transloadit.com?utm_source=sindresorhus&utm_medium=referral&utm_campaign=sponsorship&utm_content=type-fest">
|
|
37
|
-
<picture>
|
|
38
|
-
<source width="350" media="(prefers-color-scheme: dark)" srcset="https://sindresorhus.com/assets/thanks/transloadit-logo-dark.svg">
|
|
39
|
-
<source width="350" media="(prefers-color-scheme: light)" srcset="https://sindresorhus.com/assets/thanks/transloadit-logo.svg">
|
|
40
|
-
<img width="350" src="https://sindresorhus.com/assets/thanks/transloadit-logo.svg" alt="Transloadit logo">
|
|
41
|
-
</picture>
|
|
42
|
-
</a>
|
|
43
|
-
<br>
|
|
44
|
-
<br>
|
|
45
|
-
<br>
|
|
46
36
|
<a href="https://logto.io/?ref=sindre">
|
|
47
37
|
<div>
|
|
48
38
|
<picture>
|
|
@@ -129,6 +119,8 @@ Click the type names for complete docs.
|
|
|
129
119
|
- [`NonEmptyObject`](source/non-empty-object.d.ts) - Represents an object with at least 1 non-optional key.
|
|
130
120
|
- [`UnknownRecord`](source/unknown-record.d.ts) - Represents an object with `unknown` value. You probably want this instead of `{}`.
|
|
131
121
|
- [`UnknownArray`](source/unknown-array.d.ts) - Represents an array with `unknown` value.
|
|
122
|
+
- [`UnknownMap`](source/unknown-map.d.ts) - Represents a map with `unknown` key and value.
|
|
123
|
+
- [`UnknownSet`](source/unknown-set.d.ts) - Represents a set with `unknown` value.
|
|
132
124
|
- [`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/utility-types.html#omittype-keys).
|
|
133
125
|
- [`Writable`](source/writable.d.ts) - Create a type that strips `readonly` from the given type. Inverse of `Readonly<T>`.
|
|
134
126
|
- [`WritableDeep`](source/writable-deep.d.ts) - Create a deeply mutable version of an `object`/`ReadonlyMap`/`ReadonlySet`/`ReadonlyArray` type. The inverse of `ReadonlyDeep<T>`. Use `Writable<T>` if you only need one level deep.
|
|
@@ -207,6 +199,7 @@ Click the type names for complete docs.
|
|
|
207
199
|
- [`And`](source/and.d.ts) - Returns a boolean for whether two given types are both true.
|
|
208
200
|
- [`Or`](source/or.d.ts) - Returns a boolean for whether either of two given types are true.
|
|
209
201
|
- [`NonEmptyTuple`](source/non-empty-tuple.d.ts) - Matches any non-empty tuple.
|
|
202
|
+
- [`NonEmptyString`](source/non-empty-string.d.ts) - Matches any non-empty string.
|
|
210
203
|
- [`FindGlobalType`](source/find-global-type.d.ts) - Tries to find the type of a global with the given name.
|
|
211
204
|
- [`FindGlobalInstanceType`](source/find-global-type.d.ts) - Tries to find one or more types from their globally-defined constructors.
|
|
212
205
|
|
package/source/is-float.d.ts
CHANGED
|
@@ -3,31 +3,41 @@ import type {Zero} from './numeric';
|
|
|
3
3
|
/**
|
|
4
4
|
Returns a boolean for whether the given number is a float, like `1.5` or `-1.5`.
|
|
5
5
|
|
|
6
|
-
It returns `false` for `Infinity`.
|
|
7
|
-
|
|
8
6
|
Use-case:
|
|
9
7
|
- If you want to make a conditional branch based on the result of whether a number is a float or not.
|
|
10
8
|
|
|
11
9
|
@example
|
|
12
10
|
```
|
|
13
|
-
type
|
|
11
|
+
import type {IsFloat, PositiveInfinity} from "type-fest";
|
|
12
|
+
|
|
13
|
+
type A = IsFloat<1.5>;
|
|
14
14
|
//=> true
|
|
15
15
|
|
|
16
|
-
type
|
|
17
|
-
//=>
|
|
16
|
+
type B = IsFloat<-1.5>;
|
|
17
|
+
//=> true
|
|
18
18
|
|
|
19
|
-
type
|
|
19
|
+
type C = IsFloat<1e-7>;
|
|
20
20
|
//=> true
|
|
21
21
|
|
|
22
|
-
type
|
|
22
|
+
type D = IsFloat<1.0>;
|
|
23
|
+
//=> false
|
|
24
|
+
|
|
25
|
+
type E = IsFloat<PositiveInfinity>;
|
|
26
|
+
//=> false
|
|
27
|
+
|
|
28
|
+
type F = IsFloat<1.23e+21>;
|
|
23
29
|
//=> false
|
|
24
30
|
```
|
|
31
|
+
|
|
32
|
+
@category Type Guard
|
|
33
|
+
@category Numeric
|
|
25
34
|
*/
|
|
26
|
-
export type IsFloat<T> =
|
|
27
|
-
T extends number
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
export type IsFloat<T> = T extends number
|
|
36
|
+
? `${T}` extends `${number}e${infer E extends '-' | '+'}${number}`
|
|
37
|
+
? E extends '-'
|
|
38
|
+
? true
|
|
39
|
+
: false
|
|
40
|
+
: `${T}` extends `${number}.${number}`
|
|
41
|
+
? true
|
|
42
|
+
: false
|
|
33
43
|
: false;
|
package/source/is-integer.d.ts
CHANGED
|
@@ -3,38 +3,48 @@ import type {IsFloat} from './is-float';
|
|
|
3
3
|
import type {PositiveInfinity, NegativeInfinity} from './numeric';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
Returns a boolean for whether the given number is
|
|
7
|
-
|
|
8
|
-
Like [`Number#IsInteger()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/IsInteger) but for types.
|
|
6
|
+
Returns a boolean for whether the given number is an integer, like `-5`, `1.0`, or `100`.
|
|
9
7
|
|
|
10
8
|
Use-case:
|
|
11
|
-
- If you want to make a conditional branch based on the result of whether a number is
|
|
9
|
+
- If you want to make a conditional branch based on the result of whether a number is an integer or not.
|
|
12
10
|
|
|
13
11
|
@example
|
|
14
12
|
```
|
|
15
|
-
type
|
|
16
|
-
//=> true
|
|
13
|
+
import type {IsInteger, PositiveInfinity} from "type-fest";
|
|
17
14
|
|
|
18
|
-
type
|
|
15
|
+
type A = IsInteger<1>;
|
|
19
16
|
//=> true
|
|
20
17
|
|
|
21
|
-
type
|
|
18
|
+
type B = IsInteger<1.0>;
|
|
22
19
|
//=> true
|
|
23
20
|
|
|
24
|
-
type
|
|
25
|
-
//=>
|
|
21
|
+
type C = IsInteger<-1>;
|
|
22
|
+
//=> true
|
|
26
23
|
|
|
27
|
-
|
|
24
|
+
type D = IsInteger<0b10>;
|
|
25
|
+
//=> true
|
|
28
26
|
|
|
29
|
-
type
|
|
27
|
+
type E = IsInteger<0o10>;
|
|
30
28
|
//=> true
|
|
31
29
|
|
|
32
|
-
type
|
|
30
|
+
type F = IsInteger<0x10>;
|
|
33
31
|
//=> true
|
|
34
32
|
|
|
35
|
-
type
|
|
33
|
+
type G = IsInteger<1.23+21>;
|
|
36
34
|
//=> true
|
|
35
|
+
|
|
36
|
+
type H = IsInteger<1.5>;
|
|
37
|
+
//=> false
|
|
38
|
+
|
|
39
|
+
type I = IsInteger<PositiveInfinity>;
|
|
40
|
+
//=> false
|
|
41
|
+
|
|
42
|
+
type J = IsInteger<1e-7>;
|
|
43
|
+
//=> false
|
|
37
44
|
```
|
|
45
|
+
|
|
46
|
+
@category Type Guard
|
|
47
|
+
@category Numeric
|
|
38
48
|
*/
|
|
39
49
|
export type IsInteger<T> =
|
|
40
50
|
T extends bigint
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Matches any non-empty string.
|
|
3
|
+
|
|
4
|
+
This is useful when you need a string that is not empty, for example, as a function parameter.
|
|
5
|
+
|
|
6
|
+
NOTE:
|
|
7
|
+
- This returns `never` not just when instantiated with an empty string, but also when an empty string is a subtype of the instantiated type, like `string` or `Uppercase<string>`.
|
|
8
|
+
|
|
9
|
+
@example
|
|
10
|
+
```
|
|
11
|
+
import type {NonEmptyString} from 'type-fest';
|
|
12
|
+
|
|
13
|
+
declare function foo<T extends string>(string: NonEmptyString<T>): void;
|
|
14
|
+
|
|
15
|
+
foo('a');
|
|
16
|
+
//=> OK
|
|
17
|
+
|
|
18
|
+
foo('');
|
|
19
|
+
//=> Error: Argument of type '""' is not assignable to parameter of type 'never'.
|
|
20
|
+
|
|
21
|
+
declare const someString: string
|
|
22
|
+
foo(someString);
|
|
23
|
+
//=> Error: Argument of type 'string' is not assignable to parameter of type 'never'.
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
@category String
|
|
27
|
+
*/
|
|
28
|
+
export type NonEmptyString<T extends string> = '' extends T ? never : T;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Represents a map with `unknown` key and value.
|
|
3
|
+
|
|
4
|
+
Use case: You want a type that all maps can be assigned to, but you don't care about the value.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import type {UnknownMap} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
type IsMap<T> = T extends UnknownMap ? true : false;
|
|
11
|
+
|
|
12
|
+
type A = IsMap<Map<string, number>>;
|
|
13
|
+
//=> true
|
|
14
|
+
|
|
15
|
+
type B = IsMap<ReadonlyMap<number, string>>;
|
|
16
|
+
//=> true
|
|
17
|
+
|
|
18
|
+
type C = IsMap<string>;
|
|
19
|
+
//=> false
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
@category Type
|
|
23
|
+
*/
|
|
24
|
+
export type UnknownMap = ReadonlyMap<unknown, unknown>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Represents a set with `unknown` value.
|
|
3
|
+
|
|
4
|
+
Use case: You want a type that all sets can be assigned to, but you don't care about the value.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import type {UnknownSet} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
type IsSet<T> = T extends UnknownSet ? true : false;
|
|
11
|
+
|
|
12
|
+
type A = IsSet<Set<string>>;
|
|
13
|
+
//=> true
|
|
14
|
+
|
|
15
|
+
type B = IsSet<ReadonlySet<number>>;
|
|
16
|
+
//=> true
|
|
17
|
+
|
|
18
|
+
type C = IsSet<string>;
|
|
19
|
+
//=> false
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
@category Type
|
|
23
|
+
*/
|
|
24
|
+
export type UnknownSet = ReadonlySet<unknown>;
|