Skip to content

Commit e3234d7

Browse files
committed
Use import type
Closes #390
1 parent 20fa30a commit e3234d7

File tree

127 files changed

+218
-175
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+218
-175
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
],
3434
"devDependencies": {
3535
"@sindresorhus/tsconfig": "~0.7.0",
36-
"expect-type": "^0.12.0",
37-
"tsd": "^0.17.0",
38-
"typescript": ">=4.2",
36+
"expect-type": "^0.13.0",
37+
"tsd": "^0.20.0",
38+
"typescript": "^4.6.3",
3939
"xo": "^0.43.0"
4040
},
4141
"types": "./index.d.ts",

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ npm install type-fest
6767
## Usage
6868

6969
```ts
70-
import {Except} from 'type-fest';
70+
import type {Except} from 'type-fest';
7171

7272
type Foo = {
7373
unicorn: string;

source/async-return-type.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {PromiseValue} from './promise-value';
1+
import type {PromiseValue} from './promise-value';
22

33
type AsyncFunction = (...args: any[]) => Promise<unknown>;
44

@@ -9,7 +9,7 @@ There has been [discussion](https://github.com/microsoft/TypeScript/pull/35998)
99
1010
@example
1111
```ts
12-
import {AsyncReturnType} from 'type-fest';
12+
import type {AsyncReturnType} from 'type-fest';
1313
import {asyncFunction} from 'api';
1414
1515
// This type resolves to the unwrapped return type of `asyncFunction`.

source/asyncify.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {PromiseValue} from './promise-value';
2-
import {SetReturnType} from './set-return-type';
1+
import type {PromiseValue} from './promise-value';
2+
import type {SetReturnType} from './set-return-type';
33

44
/**
55
Create an async version of the given function type, by boxing the return type in `Promise` while keeping the same parameter types.
@@ -8,7 +8,7 @@ Use-case: You have two functions, one synchronous and one asynchronous that do t
88
99
@example
1010
```
11-
import {Asyncify} from 'type-fest';
11+
import type {Asyncify} from 'type-fest';
1212
1313
// Synchronous function.
1414
function getFooSync(someArg: SomeType): Foo {

source/camel-case.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {WordSeparators} from '../source/utilities';
2-
import {Split} from './split';
1+
import type {WordSeparators} from '../source/utilities';
2+
import type {Split} from './split';
33

44
/**
55
Step by step takes the first item in an array literal, formats it and adds it to a string literal, and then recursively appends the remainder.
@@ -36,7 +36,7 @@ This can be useful when, for example, converting some kebab-cased command-line f
3636
3737
@example
3838
```
39-
import {CamelCase} from 'type-fest';
39+
import type {CamelCase} from 'type-fest';
4040
4141
// Simple
4242

source/camel-cased-properties-deep.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {CamelCase} from './camel-case';
1+
import type {CamelCase} from './camel-case';
22

33
/**
44
Convert object properties to camel case recursively.
@@ -10,6 +10,8 @@ This can be useful when, for example, converting some API types from a different
1010
1111
@example
1212
```
13+
import type {CamelCasedPropertiesDeep} from 'type-fest';
14+
1315
interface User {
1416
UserId: number;
1517
UserName: string;

source/camel-cased-properties.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {CamelCase} from './camel-case';
1+
import type {CamelCase} from './camel-case';
22

33
/**
44
Convert object properties to camel case but not recursively.
@@ -10,6 +10,8 @@ This can be useful when, for example, converting some API types from a different
1010
1111
@example
1212
```
13+
import type {CamelCasedProperties} from 'type-fest';
14+
1315
interface User {
1416
UserId: number;
1517
UserName: string;

source/conditional-except.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {Except} from './except';
2-
import {ConditionalKeys} from './conditional-keys';
1+
import type {Except} from './except';
2+
import type {ConditionalKeys} from './conditional-keys';
33

44
/**
55
Exclude keys from a shape that matches the given `Condition`.
@@ -8,7 +8,7 @@ This is useful when you want to create a new type with a specific set of keys fr
88
99
@example
1010
```
11-
import {Primitive, ConditionalExcept} from 'type-fest';
11+
import type {Primitive, ConditionalExcept} from 'type-fest';
1212
1313
class Awesome {
1414
name: string;
@@ -24,7 +24,7 @@ type ExceptPrimitivesFromAwesome = ConditionalExcept<Awesome, Primitive>;
2424
2525
@example
2626
```
27-
import {ConditionalExcept} from 'type-fest';
27+
import type {ConditionalExcept} from 'type-fest';
2828
2929
interface Example {
3030
a: string;

source/conditional-keys.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Internally this is used for the `ConditionalPick` and `ConditionalExcept` types.
55
66
@example
77
```
8-
import {ConditionalKeys} from 'type-fest';
8+
import type {ConditionalKeys} from 'type-fest';
99
1010
interface Example {
1111
a: string;
@@ -22,6 +22,8 @@ To support partial types, make sure your `Condition` is a union of undefined (fo
2222
2323
@example
2424
```
25+
import type {ConditionalKeys} from 'type-fest';
26+
2527
type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
2628
//=> 'a' | 'c'
2729
```

source/conditional-pick.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ConditionalKeys} from './conditional-keys';
1+
import type {ConditionalKeys} from './conditional-keys';
22

33
/**
44
Pick keys from the shape that matches the given `Condition`.
@@ -7,7 +7,7 @@ This is useful when you want to create a new type from a specific subset of an e
77
88
@example
99
```
10-
import {Primitive, ConditionalPick} from 'type-fest';
10+
import type {Primitive, ConditionalPick} from 'type-fest';
1111
1212
class Awesome {
1313
name: string;
@@ -23,7 +23,7 @@ type PickPrimitivesFromAwesome = ConditionalPick<Awesome, Primitive>;
2323
2424
@example
2525
```
26-
import {ConditionalPick} from 'type-fest';
26+
import type {ConditionalPick} from 'type-fest';
2727
2828
interface Example {
2929
a: string;

source/delimiter-case.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {UpperCaseCharacters, WordSeparators} from '../source/utilities';
1+
import type {UpperCaseCharacters, WordSeparators} from '../source/utilities';
22

33
/**
44
Unlike a simpler split, this one includes the delimiter splitted on in the resulting array literal. This is to enable splitting on, for example, upper-case characters.
@@ -54,7 +54,7 @@ This can be useful when, for example, converting a camel-cased object property t
5454
5555
@example
5656
```
57-
import {DelimiterCase} from 'type-fest';
57+
import type {DelimiterCase} from 'type-fest';
5858
5959
// Simple
6060

source/delimiter-cased-properties-deep.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {DelimiterCase} from './delimiter-case';
1+
import type {DelimiterCase} from './delimiter-case';
22

33
/**
44
Convert object properties to delimiter case recursively.
@@ -10,6 +10,8 @@ This can be useful when, for example, converting some API types from a different
1010
1111
@example
1212
```
13+
import type {DelimiterCasedPropertiesDeep} from 'type-fest';
14+
1315
interface User {
1416
userId: number;
1517
userName: string;

source/delimiter-cased-properties.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {DelimiterCase} from './delimiter-case';
1+
import type {DelimiterCase} from './delimiter-case';
22

33
/**
44
Convert object properties to delimiter case but not recursively.
@@ -10,6 +10,8 @@ This can be useful when, for example, converting some API types from a different
1010
1111
@example
1212
```
13+
import type {DelimiterCasedProperties} from 'type-fest';
14+
1315
interface User {
1416
userId: number;
1517
userName: string;

source/entries.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ArrayEntry, MapEntry, ObjectEntry, SetEntry} from './entry';
1+
import type {ArrayEntry, MapEntry, ObjectEntry, SetEntry} from './entry';
22

33
type ArrayEntries<BaseType extends readonly unknown[]> = Array<ArrayEntry<BaseType>>;
44
type MapEntries<BaseType> = Array<MapEntry<BaseType>>;
@@ -14,7 +14,7 @@ For example the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/R
1414
1515
@example
1616
```
17-
import {Entries} from 'type-fest';
17+
import type {Entries} from 'type-fest';
1818
1919
interface Example {
2020
someKey: number;

source/entry.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ For example the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/R
1515
1616
@example
1717
```
18-
import {Entry} from 'type-fest';
18+
import type {Entry} from 'type-fest';
1919
2020
interface Example {
2121
someKey: number;

source/except.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {IsEqual} from './internal';
1+
import type {IsEqual} from './internal';
22

33
/**
44
Filter out keys from an object.
@@ -38,7 +38,7 @@ This type was proposed to the TypeScript team, which declined it, saying they pr
3838
3939
@example
4040
```
41-
import {Except} from 'type-fest';
41+
import type {Except} from 'type-fest';
4242
4343
type Foo = {
4444
a: number;

source/fixed-length-array.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Use-cases:
1515
1616
@example
1717
```
18-
import {FixedLengthArray} from 'type-fest';
18+
import type {FixedLengthArray} from 'type-fest';
1919
2020
type FencingTeam = FixedLengthArray<string, 3>;
2121

source/get.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {StringDigit} from '../source/utilities';
2-
import {Split} from './split';
3-
import {StringKeyOf} from './string-key-of';
1+
import type {StringDigit} from '../source/utilities';
2+
import type {Split} from './split';
3+
import type {StringKeyOf} from './string-key-of';
44

55
type GetOptions = {
66
strict?: boolean;
@@ -141,7 +141,7 @@ Use-case: Retrieve a property from deep inside an API response or some other com
141141
142142
@example
143143
```
144-
import {Get} from 'type-fest';
144+
import type {Get} from 'type-fest';
145145
import * as lodash from 'lodash';
146146
147147
const get = <BaseType, Path extends string | readonly string[]>(object: BaseType, path: Path): Get<BaseType, Path> =>

source/includes.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {IsEqual} from './internal';
1+
import type {IsEqual} from './internal';
22

33
/**
44
Returns a boolean for whether the given array includes the given item.
@@ -7,7 +7,7 @@ This can be useful if another type wants to make a decision based on whether the
77
88
@example
99
```
10-
import {Includes} from 'type-fest';
10+
import type {Includes} from 'type-fest';
1111
1212
type hasRed<array extends any[]> = Includes<array, 'red'>;
1313
```

source/internal.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Primitive} from './primitive';
1+
import type {Primitive} from './primitive';
22

33
/**
44
Returns a boolean for whether the two given types are equal.

source/invariant-of.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Opaque} from './opaque';
1+
import type {Opaque} from './opaque';
22

33
/**
44
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.
@@ -9,6 +9,8 @@ Use-case:
99
1010
@example
1111
```
12+
import type {InvariantOf} from 'type-fest';
13+
1214
class Animal {
1315
constructor(public name: string){}
1416
}
@@ -32,6 +34,8 @@ invariantAnimalArray = invariantCatArray; // Error: Type 'InvariantOf<Cat>[]' is
3234
3335
@example
3436
```
37+
import type {InvariantOf} from 'type-fest';
38+
3539
// In covariance (default)
3640
3741
interface FooBar {

source/iterable-element.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Here is an example of `IterableElement` in action with a generator function:
99
1010
@example
1111
```
12+
import type {IterableElement} from 'type-fest';
13+
1214
function * iAmGenerator() {
1315
yield 1;
1416
yield 2;
@@ -21,6 +23,8 @@ And here is an example with an async generator:
2123
2224
@example
2325
```
26+
import type {IterableElement} from 'type-fest';
27+
2428
async function * iAmGeneratorAsync() {
2529
yield 'hi';
2630
yield true;
@@ -35,6 +39,8 @@ An example with an array of strings:
3539
3640
@example
3741
```
42+
import type {IterableElement} from 'type-fest';
43+
3844
type MeString = IterableElement<string[]>
3945
```
4046

source/join.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Use-case: Defining key paths in a nested object. For example, for dot-notation f
55
66
@example
77
```
8-
import {Join} from 'type-fest';
8+
import type {Join} from 'type-fest';
99
1010
// Mixed (strings & numbers) items; result is: 'foo.0.baz'
1111
const path: Join<['foo', 0, 'baz'], '.'> = ['foo', 0, 'baz'].join('.');

source/jsonify.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {JsonPrimitive, JsonValue} from './basic';
1+
import type {JsonPrimitive, JsonValue} from './basic';
22

33
// Note: The return value has to be `any` and not `unknown` so it can match `void`.
44
type NotJsonable = ((...args: any[]) => any) | undefined;
@@ -23,6 +23,8 @@ An interface cannot be structurally compared to `JsonValue` because an interface
2323
2424
@example
2525
```
26+
import type {Jsonify} from 'type-fest';
27+
2628
interface Geometry {
2729
type: 'Point' | 'Polygon';
2830
coordinates: [number, number];
@@ -51,6 +53,8 @@ Non-JSON values such as `Date` implement `.toJSON()`, so they can be transformed
5153
5254
@example
5355
```
56+
import type {Jsonify} from 'type-fest';
57+
5458
const time = {
5559
timeValue: new Date()
5660
};

0 commit comments

Comments
 (0)