Skip to content

Commit 1bd0fa2

Browse files
committed
Drop tsd for tests in favor of expect-type
`tsd` is a somewhat heavy-weight dependency that is unnecessary considering that `expect-type` is already a depdency of `type-fest`.
1 parent e11d30b commit 1bd0fa2

File tree

80 files changed

+804
-790
lines changed

Some content is hidden

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

80 files changed

+804
-790
lines changed

.github/contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- Please help review the other open pull requests. If there are no open pull requests, provide some feedback on some of the open issues.
77
- Create a new file in the `test-d` directory and write at least one type test.
88
- See the other tests for inspiration.
9-
- If it makes sense, also write a negative test using [`expectNotAssignable()`](https://github.com/SamVerschueren/tsd#expectnotassignabletexpression-any) or, to test other diagnostics, [`expectError()`](https://github.com/SamVerschueren/tsd#expecterrort--anyexpression-t).
9+
- If it makes sense, also write a negative test using [`expectTypeOf().not`](https://github.com/mmkal/expect-type#features) or, to test other diagnostics, `@ts-expect-error`.
1010
- Don't use one-character type names like `T` and `U`. Use descriptive names. See the existing types for inspiration.
1111
- Write a good documentation comment that includes:
1212
- Write a short and clear description of what the type does.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"node": ">=14.16"
1616
},
1717
"scripts": {
18-
"test": "xo && tsd && tsc && node script/test/source-files-extension.js"
18+
"test": "xo && tsc && node script/test/source-files-extension.js"
1919
},
2020
"files": [
2121
"index.d.ts",
@@ -36,7 +36,6 @@
3636
"devDependencies": {
3737
"@sindresorhus/tsconfig": "~0.7.0",
3838
"expect-type": "^0.14.2",
39-
"tsd": "^0.24.1",
4039
"typescript": "^4.8.3",
4140
"xo": "^0.52.2"
4241
},

test-d/async-return-type.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {expectNotAssignable, expectType} from 'tsd';
1+
import {expectTypeOf} from 'expect-type';
22
import type {AsyncReturnType} from '../index';
33

44
async function asyncFunction(): Promise<number> {
@@ -9,6 +9,6 @@ type Value = AsyncReturnType<typeof asyncFunction>;
99

1010
// eslint-disable-next-line @typescript-eslint/no-floating-promises
1111
asyncFunction().then(value => {
12-
expectType<Value>(value);
13-
expectNotAssignable<string>(value);
12+
expectTypeOf(value).toEqualTypeOf<Value>();
13+
expectTypeOf(value).not.toMatchTypeOf<string>();
1414
});

test-d/asyncify.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import {expectType, expectError} from 'tsd';
1+
import {expectTypeOf} from 'expect-type';
22
import type {Asyncify} from '../index';
33

44
declare function getFooSync(name: string): RegExp;
55
declare function getFooWithThisArgSync(this: Date, name: string): RegExp;
66

77
// Basic usage.
88
declare const getFooAsync1: Asyncify<typeof getFooSync>;
9-
expectType<(name: string) => Promise<RegExp>>(getFooAsync1);
9+
expectTypeOf(getFooAsync1).toEqualTypeOf<(name: string) => Promise<RegExp>>();
1010

1111
// Noops with async functions.
1212
declare const getFooAsync2: Asyncify<typeof getFooAsync1>;
13-
expectType<typeof getFooAsync1>(getFooAsync2);
13+
expectTypeOf(getFooAsync2).toEqualTypeOf<typeof getFooAsync1>();
1414

1515
// Respects `thisArg`.
1616
declare const getFooWithThisArgAsync1: Asyncify<typeof getFooWithThisArgSync>;
1717
const callResult = getFooWithThisArgAsync1.call(new Date(), 'foo');
18-
expectType<Promise<RegExp>>(callResult);
19-
expectError(getFooWithThisArgAsync1.call('not-date', 'foo'));
18+
expectTypeOf(callResult).toEqualTypeOf<Promise<RegExp>>();
19+
// @ts-expect-error
20+
void getFooWithThisArgAsync1.call('not-date', 'foo');

test-d/camel-case.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
1-
import {expectType, expectAssignable} from 'tsd';
1+
import {expectTypeOf} from 'expect-type';
22
import type {CamelCase, Split} from '../index';
33

44
// Split
55
const prefixSplit: Split<'--very-prefixed', '-'> = ['', '', 'very', 'prefixed'];
6-
expectType<['', '', 'very', 'prefixed']>(prefixSplit);
6+
expectTypeOf(prefixSplit).toEqualTypeOf<['', '', 'very', 'prefixed']>();
77

88
// CamelCase
99
const camelFromPascal: CamelCase<'FooBar'> = 'fooBar';
10-
expectType<'fooBar'>(camelFromPascal);
10+
expectTypeOf(camelFromPascal).toEqualTypeOf<'fooBar'>();
1111

1212
const camelFromKebab: CamelCase<'foo-bar'> = 'fooBar';
13-
expectType<'fooBar'>(camelFromKebab);
13+
expectTypeOf(camelFromKebab).toEqualTypeOf<'fooBar'>();
1414

1515
const camelFromComplexKebab: CamelCase<'foo-bar-abc-123'> = 'fooBarAbc123';
16-
expectType<'fooBarAbc123'>(camelFromComplexKebab);
16+
expectTypeOf(camelFromComplexKebab).toEqualTypeOf<'fooBarAbc123'>();
1717

1818
const camelFromSpace: CamelCase<'foo bar'> = 'fooBar';
19-
expectType<'fooBar'>(camelFromSpace);
19+
expectTypeOf(camelFromSpace).toEqualTypeOf<'fooBar'>();
2020

2121
const camelFromSnake: CamelCase<'foo_bar'> = 'fooBar';
22-
expectType<'fooBar'>(camelFromSnake);
22+
expectTypeOf(camelFromSnake).toEqualTypeOf<'fooBar'>();
2323

2424
const noDelimiterFromMono: CamelCase<'foobar'> = 'foobar';
25-
expectType<'foobar'>(noDelimiterFromMono);
25+
expectTypeOf(noDelimiterFromMono).toEqualTypeOf<'foobar'>();
2626

2727
const camelFromMixed: CamelCase<'foo-bar_abc xyzBarFoo'> = 'fooBarAbcXyzBarFoo';
28-
expectType<'fooBarAbcXyzBarFoo'>(camelFromMixed);
28+
expectTypeOf(camelFromMixed).toEqualTypeOf<'fooBarAbcXyzBarFoo'>();
2929

3030
const camelFromVendorPrefixedCssProperty: CamelCase<'-webkit-animation'> = 'webkitAnimation';
31-
expectType<'webkitAnimation'>(camelFromVendorPrefixedCssProperty);
31+
expectTypeOf(camelFromVendorPrefixedCssProperty).toEqualTypeOf<'webkitAnimation'>();
3232

3333
const camelFromDoublePrefixedKebab: CamelCase<'--very-prefixed'> = 'veryPrefixed';
34-
expectType<'veryPrefixed'>(camelFromDoublePrefixedKebab);
34+
expectTypeOf(camelFromDoublePrefixedKebab).toEqualTypeOf<'veryPrefixed'>();
3535

3636
const camelFromRepeatedSeparators: CamelCase<'foo____bar'> = 'fooBar';
37-
expectType<'fooBar'>(camelFromRepeatedSeparators);
37+
expectTypeOf(camelFromRepeatedSeparators).toEqualTypeOf<'fooBar'>();
3838

3939
const camelFromUppercase: CamelCase<'FOO'> = 'foo';
40-
expectType<'foo'>(camelFromUppercase);
40+
expectTypeOf(camelFromUppercase).toEqualTypeOf<'foo'>();
4141

4242
const camelFromLowercase: CamelCase<'foo'> = 'foo';
43-
expectType<'foo'>(camelFromLowercase);
43+
expectTypeOf(camelFromLowercase).toEqualTypeOf<'foo'>();
4444

4545
const camelFromScreamingSnakeCase: CamelCase<'FOO_BAR'> = 'fooBar';
46-
expectType<'fooBar'>(camelFromScreamingSnakeCase);
46+
expectTypeOf(camelFromScreamingSnakeCase).toEqualTypeOf<'fooBar'>();
4747

4848
const camelFromScreamingKebabCase: CamelCase<'FOO-BAR'> = 'fooBar';
49-
expectType<'fooBar'>(camelFromScreamingKebabCase);
49+
expectTypeOf(camelFromScreamingKebabCase).toEqualTypeOf<'fooBar'>();
5050

5151
// Verifying example
5252
type CamelCasedProperties<T> = {
@@ -62,11 +62,11 @@ type RawOptions = {
6262
'OTHER-FIELD': boolean;
6363
};
6464

65-
expectAssignable<CamelCasedProperties<RawOptions>>({
65+
expectTypeOf({
6666
dryRun: true,
6767
fullFamilyName: 'bar.js',
6868
foo: 123,
6969
bar: 'foo',
7070
quzQux: 6,
7171
otherField: false,
72-
});
72+
}).toMatchTypeOf<CamelCasedProperties<RawOptions>>();

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import {expectType} from 'tsd';
1+
import {expectTypeOf} from 'expect-type';
22
import type {CamelCasedPropertiesDeep} from '../index';
33

44
declare const foo: CamelCasedPropertiesDeep<{A: {B: number; C: Array<{D: string}>}}>;
55

6-
expectType<{a: {b: number; c: Array<{d: string}>}}>(foo);
6+
expectTypeOf(foo).toEqualTypeOf<{a: {b: number; c: Array<{d: string}>}}>();
77

88
declare const fooBar: CamelCasedPropertiesDeep<() => {a: string}>;
9-
expectType<() => {a: string}>(fooBar);
9+
expectTypeOf(fooBar).toEqualTypeOf<() => {a: string}>();
1010

1111
declare const bar: CamelCasedPropertiesDeep<Set<{fooBar: string}>>;
12-
expectType<Set<{fooBar: string}>>(bar);
12+
expectTypeOf(bar).toEqualTypeOf<Set<{fooBar: string}>>();
1313

1414
// Verify example
1515
type User = {
@@ -46,4 +46,4 @@ const result: CamelCasedPropertiesDeep<UserWithFriends> = {
4646
},
4747
],
4848
};
49-
expectType<CamelCasedPropertiesDeep<UserWithFriends>>(result);
49+
expectTypeOf(result).toEqualTypeOf<CamelCasedPropertiesDeep<UserWithFriends>>();

test-d/camel-cased-properties.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import {expectType} from 'tsd';
1+
import {expectTypeOf} from 'expect-type';
22
import type {CamelCasedProperties} from '../index';
33

44
declare const foo: CamelCasedProperties<{A: number; B: {C: string}}>;
55

6-
expectType<{a: number; b: {C: string}}>(foo);
6+
expectTypeOf(foo).toEqualTypeOf<{a: number; b: {C: string}}>();
77

88
declare const bar: CamelCasedProperties<Array<{helloWorld: string}>>;
9-
expectType<Array<{helloWorld: string}>>(bar);
9+
expectTypeOf(bar).toEqualTypeOf<Array<{helloWorld: string}>>();
1010

1111
declare const fooBar: CamelCasedProperties<() => {a: string}>;
12-
expectType<() => {a: string}>(fooBar);
12+
expectTypeOf(fooBar).toEqualTypeOf<() => {a: string}>();
1313

1414
// Verify example
1515
type User = {
@@ -21,4 +21,4 @@ const result: CamelCasedProperties<User> = {
2121
userId: 1,
2222
userName: 'Tom',
2323
};
24-
expectType<CamelCasedProperties<User>>(result);
24+
expectTypeOf(result).toEqualTypeOf<CamelCasedProperties<User>>();

test-d/class.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {expectError} from 'tsd';
21
import type {Constructor} from '../index';
32

43
class Foo {
@@ -15,7 +14,9 @@ function fn(Cls: Constructor<Foo>): Foo {
1514
}
1615

1716
function fn2(Cls: Constructor<Foo, [number, number]>): Foo {
18-
expectError(new Cls(1, ''));
17+
// @ts-expect-error
18+
// eslint-disable-next-line no-new
19+
new Cls(1, '');
1920
return new Cls(1, 2);
2021
}
2122

test-d/conditional-except.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {expectType} from 'tsd';
1+
import {expectTypeOf} from 'expect-type';
22
import type {ConditionalExcept, Primitive} from '../index';
33

44
class Awesome {
@@ -19,10 +19,10 @@ type Example = {
1919
};
2020

2121
declare const exampleConditionalExcept: ConditionalExcept<Example, string>;
22-
expectType<{b?: string | number; c?: string; d: Record<string, unknown>}>(exampleConditionalExcept);
22+
expectTypeOf(exampleConditionalExcept).toEqualTypeOf<{b?: string | number; c?: string; d: Record<string, unknown>}>();
2323

2424
declare const awesomeConditionalExcept: ConditionalExcept<Awesome, Primitive>;
25-
expectType<{run: () => void}>(awesomeConditionalExcept);
25+
expectTypeOf(awesomeConditionalExcept).toEqualTypeOf<{run: () => void}>();
2626

2727
declare const exampleConditionalExceptWithUndefined: ConditionalExcept<Example, string | undefined>;
28-
expectType<{b?: string | number; d: Record<string, unknown>}>(exampleConditionalExceptWithUndefined);
28+
expectTypeOf(exampleConditionalExceptWithUndefined).toEqualTypeOf<{b?: string | number; d: Record<string, unknown>}>();

test-d/conditional-keys.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {expectType} from 'tsd';
1+
import {expectTypeOf} from 'expect-type';
22
import type {ConditionalKeys} from '../index';
33

44
type Example = {
@@ -9,7 +9,7 @@ type Example = {
99
};
1010

1111
declare const exampleConditionalKeys: ConditionalKeys<Example, string>;
12-
expectType<'a'>(exampleConditionalKeys);
12+
expectTypeOf(exampleConditionalKeys).toEqualTypeOf<'a'>();
1313

1414
declare const exampleConditionalKeysWithUndefined: ConditionalKeys<Example, string | undefined>;
15-
expectType<'a' | 'c'>(exampleConditionalKeysWithUndefined);
15+
expectTypeOf(exampleConditionalKeysWithUndefined).toEqualTypeOf<'a' | 'c'>();

0 commit comments

Comments
 (0)