diff --git a/.github/contributing.md b/.github/contributing.md index f70704454..0bfe1d8a3 100644 --- a/.github/contributing.md +++ b/.github/contributing.md @@ -6,7 +6,7 @@ - Please help review the other open pull requests. If there are no open pull requests, provide some feedback on some of the open issues. - Create a new file in the `test-d` directory and write at least one type test. - See the other tests for inspiration. - - 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). + - 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`. - Don't use one-character type names like `T` and `U`. Use descriptive names. See the existing types for inspiration. - Write a good documentation comment that includes: - Write a short and clear description of what the type does. diff --git a/package.json b/package.json index a2c282cce..b30747595 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "node": ">=14.16" }, "scripts": { - "test": "xo && tsd && tsc && node script/test/source-files-extension.js" + "test": "xo && tsc && node script/test/source-files-extension.js" }, "files": [ "index.d.ts", @@ -36,7 +36,6 @@ "devDependencies": { "@sindresorhus/tsconfig": "~0.7.0", "expect-type": "^0.14.2", - "tsd": "^0.24.1", "typescript": "^4.8.3", "xo": "^0.52.2" }, diff --git a/test-d/async-return-type.ts b/test-d/async-return-type.ts index bd1b3efe4..e2bdc0700 100644 --- a/test-d/async-return-type.ts +++ b/test-d/async-return-type.ts @@ -1,4 +1,4 @@ -import {expectNotAssignable, expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {AsyncReturnType} from '../index'; async function asyncFunction(): Promise { @@ -9,6 +9,6 @@ type Value = AsyncReturnType; // eslint-disable-next-line @typescript-eslint/no-floating-promises asyncFunction().then(value => { - expectType(value); - expectNotAssignable(value); + expectTypeOf(value).toEqualTypeOf(); + expectTypeOf(value).not.toMatchTypeOf(); }); diff --git a/test-d/asyncify.ts b/test-d/asyncify.ts index f23148d03..0835c76db 100644 --- a/test-d/asyncify.ts +++ b/test-d/asyncify.ts @@ -1,4 +1,4 @@ -import {expectType, expectError} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {Asyncify} from '../index'; declare function getFooSync(name: string): RegExp; @@ -6,14 +6,15 @@ declare function getFooWithThisArgSync(this: Date, name: string): RegExp; // Basic usage. declare const getFooAsync1: Asyncify; -expectType<(name: string) => Promise>(getFooAsync1); +expectTypeOf(getFooAsync1).toEqualTypeOf<(name: string) => Promise>(); // Noops with async functions. declare const getFooAsync2: Asyncify; -expectType(getFooAsync2); +expectTypeOf(getFooAsync2).toEqualTypeOf(); // Respects `thisArg`. declare const getFooWithThisArgAsync1: Asyncify; const callResult = getFooWithThisArgAsync1.call(new Date(), 'foo'); -expectType>(callResult); -expectError(getFooWithThisArgAsync1.call('not-date', 'foo')); +expectTypeOf(callResult).toEqualTypeOf>(); +// @ts-expect-error +void getFooWithThisArgAsync1.call('not-date', 'foo'); diff --git a/test-d/camel-case.ts b/test-d/camel-case.ts index bf056cf7d..9b15745be 100644 --- a/test-d/camel-case.ts +++ b/test-d/camel-case.ts @@ -1,52 +1,52 @@ -import {expectType, expectAssignable} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {CamelCase, Split} from '../index'; // Split const prefixSplit: Split<'--very-prefixed', '-'> = ['', '', 'very', 'prefixed']; -expectType<['', '', 'very', 'prefixed']>(prefixSplit); +expectTypeOf(prefixSplit).toEqualTypeOf<['', '', 'very', 'prefixed']>(); // CamelCase const camelFromPascal: CamelCase<'FooBar'> = 'fooBar'; -expectType<'fooBar'>(camelFromPascal); +expectTypeOf(camelFromPascal).toEqualTypeOf<'fooBar'>(); const camelFromKebab: CamelCase<'foo-bar'> = 'fooBar'; -expectType<'fooBar'>(camelFromKebab); +expectTypeOf(camelFromKebab).toEqualTypeOf<'fooBar'>(); const camelFromComplexKebab: CamelCase<'foo-bar-abc-123'> = 'fooBarAbc123'; -expectType<'fooBarAbc123'>(camelFromComplexKebab); +expectTypeOf(camelFromComplexKebab).toEqualTypeOf<'fooBarAbc123'>(); const camelFromSpace: CamelCase<'foo bar'> = 'fooBar'; -expectType<'fooBar'>(camelFromSpace); +expectTypeOf(camelFromSpace).toEqualTypeOf<'fooBar'>(); const camelFromSnake: CamelCase<'foo_bar'> = 'fooBar'; -expectType<'fooBar'>(camelFromSnake); +expectTypeOf(camelFromSnake).toEqualTypeOf<'fooBar'>(); const noDelimiterFromMono: CamelCase<'foobar'> = 'foobar'; -expectType<'foobar'>(noDelimiterFromMono); +expectTypeOf(noDelimiterFromMono).toEqualTypeOf<'foobar'>(); const camelFromMixed: CamelCase<'foo-bar_abc xyzBarFoo'> = 'fooBarAbcXyzBarFoo'; -expectType<'fooBarAbcXyzBarFoo'>(camelFromMixed); +expectTypeOf(camelFromMixed).toEqualTypeOf<'fooBarAbcXyzBarFoo'>(); const camelFromVendorPrefixedCssProperty: CamelCase<'-webkit-animation'> = 'webkitAnimation'; -expectType<'webkitAnimation'>(camelFromVendorPrefixedCssProperty); +expectTypeOf(camelFromVendorPrefixedCssProperty).toEqualTypeOf<'webkitAnimation'>(); const camelFromDoublePrefixedKebab: CamelCase<'--very-prefixed'> = 'veryPrefixed'; -expectType<'veryPrefixed'>(camelFromDoublePrefixedKebab); +expectTypeOf(camelFromDoublePrefixedKebab).toEqualTypeOf<'veryPrefixed'>(); const camelFromRepeatedSeparators: CamelCase<'foo____bar'> = 'fooBar'; -expectType<'fooBar'>(camelFromRepeatedSeparators); +expectTypeOf(camelFromRepeatedSeparators).toEqualTypeOf<'fooBar'>(); const camelFromUppercase: CamelCase<'FOO'> = 'foo'; -expectType<'foo'>(camelFromUppercase); +expectTypeOf(camelFromUppercase).toEqualTypeOf<'foo'>(); const camelFromLowercase: CamelCase<'foo'> = 'foo'; -expectType<'foo'>(camelFromLowercase); +expectTypeOf(camelFromLowercase).toEqualTypeOf<'foo'>(); const camelFromScreamingSnakeCase: CamelCase<'FOO_BAR'> = 'fooBar'; -expectType<'fooBar'>(camelFromScreamingSnakeCase); +expectTypeOf(camelFromScreamingSnakeCase).toEqualTypeOf<'fooBar'>(); const camelFromScreamingKebabCase: CamelCase<'FOO-BAR'> = 'fooBar'; -expectType<'fooBar'>(camelFromScreamingKebabCase); +expectTypeOf(camelFromScreamingKebabCase).toEqualTypeOf<'fooBar'>(); // Verifying example type CamelCasedProperties = { @@ -62,11 +62,11 @@ type RawOptions = { 'OTHER-FIELD': boolean; }; -expectAssignable>({ +expectTypeOf({ dryRun: true, fullFamilyName: 'bar.js', foo: 123, bar: 'foo', quzQux: 6, otherField: false, -}); +}).toMatchTypeOf>(); diff --git a/test-d/camel-cased-properties-deep.ts b/test-d/camel-cased-properties-deep.ts index b191c344a..9ac150727 100644 --- a/test-d/camel-cased-properties-deep.ts +++ b/test-d/camel-cased-properties-deep.ts @@ -1,15 +1,15 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {CamelCasedPropertiesDeep} from '../index'; declare const foo: CamelCasedPropertiesDeep<{A: {B: number; C: Array<{D: string}>}}>; -expectType<{a: {b: number; c: Array<{d: string}>}}>(foo); +expectTypeOf(foo).toEqualTypeOf<{a: {b: number; c: Array<{d: string}>}}>(); declare const fooBar: CamelCasedPropertiesDeep<() => {a: string}>; -expectType<() => {a: string}>(fooBar); +expectTypeOf(fooBar).toEqualTypeOf<() => {a: string}>(); declare const bar: CamelCasedPropertiesDeep>; -expectType>(bar); +expectTypeOf(bar).toEqualTypeOf>(); // Verify example type User = { @@ -46,4 +46,4 @@ const result: CamelCasedPropertiesDeep = { }, ], }; -expectType>(result); +expectTypeOf(result).toEqualTypeOf>(); diff --git a/test-d/camel-cased-properties.ts b/test-d/camel-cased-properties.ts index 0331f0f57..d271f6d8b 100644 --- a/test-d/camel-cased-properties.ts +++ b/test-d/camel-cased-properties.ts @@ -1,15 +1,15 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {CamelCasedProperties} from '../index'; declare const foo: CamelCasedProperties<{A: number; B: {C: string}}>; -expectType<{a: number; b: {C: string}}>(foo); +expectTypeOf(foo).toEqualTypeOf<{a: number; b: {C: string}}>(); declare const bar: CamelCasedProperties>; -expectType>(bar); +expectTypeOf(bar).toEqualTypeOf>(); declare const fooBar: CamelCasedProperties<() => {a: string}>; -expectType<() => {a: string}>(fooBar); +expectTypeOf(fooBar).toEqualTypeOf<() => {a: string}>(); // Verify example type User = { @@ -21,4 +21,4 @@ const result: CamelCasedProperties = { userId: 1, userName: 'Tom', }; -expectType>(result); +expectTypeOf(result).toEqualTypeOf>(); diff --git a/test-d/class.ts b/test-d/class.ts index de40cfafb..70d39cedb 100644 --- a/test-d/class.ts +++ b/test-d/class.ts @@ -1,4 +1,3 @@ -import {expectError} from 'tsd'; import type {Constructor} from '../index'; class Foo { @@ -15,7 +14,9 @@ function fn(Cls: Constructor): Foo { } function fn2(Cls: Constructor): Foo { - expectError(new Cls(1, '')); + // @ts-expect-error + // eslint-disable-next-line no-new + new Cls(1, ''); return new Cls(1, 2); } diff --git a/test-d/conditional-except.ts b/test-d/conditional-except.ts index e8c74075c..47878bbfe 100644 --- a/test-d/conditional-except.ts +++ b/test-d/conditional-except.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {ConditionalExcept, Primitive} from '../index'; class Awesome { @@ -19,10 +19,10 @@ type Example = { }; declare const exampleConditionalExcept: ConditionalExcept; -expectType<{b?: string | number; c?: string; d: Record}>(exampleConditionalExcept); +expectTypeOf(exampleConditionalExcept).toEqualTypeOf<{b?: string | number; c?: string; d: Record}>(); declare const awesomeConditionalExcept: ConditionalExcept; -expectType<{run: () => void}>(awesomeConditionalExcept); +expectTypeOf(awesomeConditionalExcept).toEqualTypeOf<{run: () => void}>(); declare const exampleConditionalExceptWithUndefined: ConditionalExcept; -expectType<{b?: string | number; d: Record}>(exampleConditionalExceptWithUndefined); +expectTypeOf(exampleConditionalExceptWithUndefined).toEqualTypeOf<{b?: string | number; d: Record}>(); diff --git a/test-d/conditional-keys.ts b/test-d/conditional-keys.ts index 47ec270e1..88c1833aa 100644 --- a/test-d/conditional-keys.ts +++ b/test-d/conditional-keys.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {ConditionalKeys} from '../index'; type Example = { @@ -9,7 +9,7 @@ type Example = { }; declare const exampleConditionalKeys: ConditionalKeys; -expectType<'a'>(exampleConditionalKeys); +expectTypeOf(exampleConditionalKeys).toEqualTypeOf<'a'>(); declare const exampleConditionalKeysWithUndefined: ConditionalKeys; -expectType<'a' | 'c'>(exampleConditionalKeysWithUndefined); +expectTypeOf(exampleConditionalKeysWithUndefined).toEqualTypeOf<'a' | 'c'>(); diff --git a/test-d/conditional-pick-deep.ts b/test-d/conditional-pick-deep.ts index 79f4ac0b2..7748bcc0d 100644 --- a/test-d/conditional-pick-deep.ts +++ b/test-d/conditional-pick-deep.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {ConditionalPickDeep} from '../index'; type Example = { @@ -17,22 +17,22 @@ type Example = { }; declare const stringPick: ConditionalPickDeep; -expectType<{a: string; c: {d: string}}>(stringPick); +expectTypeOf(stringPick).toEqualTypeOf<{a: string; c: {d: string}}>(); declare const stringPickOptional: ConditionalPickDeep; -expectType<{a: string; c: {d: string; e: {f?: string}}}>(stringPickOptional); +expectTypeOf(stringPickOptional).toEqualTypeOf<{a: string; c: {d: string; e: {f?: string}}}>(); declare const stringPickOptionalOnly: ConditionalPickDeep; -expectType<{c: {e: {f?: string}}}>(stringPickOptionalOnly); +expectTypeOf(stringPickOptionalOnly).toEqualTypeOf<{c: {e: {f?: string}}}>(); declare const booleanPick: ConditionalPickDeep; -expectType<{c: {e: {g?: boolean}; j: boolean}}>(booleanPick); +expectTypeOf(booleanPick).toEqualTypeOf<{c: {e: {g?: boolean}; j: boolean}}>(); declare const numberPick: ConditionalPickDeep; -expectType<{}>(numberPick); +expectTypeOf(numberPick).toEqualTypeOf<{}>(); declare const stringOrBooleanPick: ConditionalPickDeep; -expectType<{ +expectTypeOf(stringOrBooleanPick).toEqualTypeOf<{ a: string; b: string | boolean; c: { @@ -40,7 +40,7 @@ expectType<{ e: {h: string | boolean}; j: boolean; }; -}>(stringOrBooleanPick); +}>(); declare const stringOrBooleanPickOnly: ConditionalPickDeep; -expectType<{b: string | boolean; c: {e: {h: string | boolean}}}>(stringOrBooleanPickOnly); +expectTypeOf(stringOrBooleanPickOnly).toEqualTypeOf<{b: string | boolean; c: {e: {h: string | boolean}}}>(); diff --git a/test-d/conditional-pick.ts b/test-d/conditional-pick.ts index e847d5410..4e4ec517a 100644 --- a/test-d/conditional-pick.ts +++ b/test-d/conditional-pick.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {ConditionalPick, Primitive} from '../index'; class Awesome { @@ -19,10 +19,10 @@ type Example = { }; declare const exampleConditionalPick: ConditionalPick; -expectType< {a: string}>(exampleConditionalPick); +expectTypeOf(exampleConditionalPick).toEqualTypeOf< {a: string}>(); declare const awesomeConditionalPick: ConditionalPick; -expectType<{name: string; successes: number; failures: bigint}>(awesomeConditionalPick); +expectTypeOf(awesomeConditionalPick).toEqualTypeOf<{name: string; successes: number; failures: bigint}>(); declare const exampleConditionalPickWithUndefined: ConditionalPick; -expectType<{a: string; c?: string}>(exampleConditionalPickWithUndefined); +expectTypeOf(exampleConditionalPickWithUndefined).toEqualTypeOf<{a: string; c?: string}>(); diff --git a/test-d/conditional-simplify.ts b/test-d/conditional-simplify.ts index 1e1d3a1bf..408fa0b66 100644 --- a/test-d/conditional-simplify.ts +++ b/test-d/conditional-simplify.ts @@ -1,4 +1,4 @@ -import {expectNotAssignable, expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {ConditionalSimplify, ConditionalSimplifyDeep} from '../source/conditional-simplify'; type Position = {top: number; left: number}; @@ -11,7 +11,7 @@ type PositionAndSizeSimplified = ConditionalSimplify(positionAndSize); +expectTypeOf(positionAndSize).toEqualTypeOf(); // Exclude function type to be simplified. type SomeFunction = (type: string) => string; @@ -21,8 +21,8 @@ type SimplifiedFunctionPass = ConditionalSimplify; // Re declare const simplifiedFunctionFail: SimplifiedFunctionFail; declare const simplifiedFunctionPass: SimplifiedFunctionPass; -expectNotAssignable(simplifiedFunctionFail); -expectType(simplifiedFunctionPass); +expectTypeOf(simplifiedFunctionFail).not.toMatchTypeOf(); +expectTypeOf(simplifiedFunctionPass).toEqualTypeOf(); // Should simplify interface deeply. type SomeNode = { @@ -34,7 +34,7 @@ type SomeNode = { type SomeNodeSimplified = ConditionalSimplifyDeep; const someNode = {parent: positionAndSize, childs: [{parent: positionAndSize}, {parent: positionAndSize}]}; -expectType(someNode); +expectTypeOf(someNode).toEqualTypeOf(); // Should simplify interface deeply excluding Function type. // TODO: Convert this to a `type`. @@ -55,8 +55,8 @@ type MovableNodeSimplifiedPass = ConditionalSimplifyDeep(movableNodeSimplifiedFail); -expectType(movableNodeSimplifiedPass); +expectTypeOf(movableNodeSimplifiedFail).not.toMatchTypeOf(); +expectTypeOf(movableNodeSimplifiedPass).toEqualTypeOf(); const movablePosition = { top: 42, @@ -72,12 +72,12 @@ const movableNode = { left: {position: movablePosition, size}, }; -expectType(movableNode); +expectTypeOf(movableNode).toEqualTypeOf(); // Should exclude `Function` and `Size` type (mainly visual, mouse over the statement). type ExcludeFunctionAndSize1 = ConditionalSimplifyDeep; -expectType(movableNode); +expectTypeOf(movableNode).toEqualTypeOf(); // Same as above but using `IncludeType` parameter (mainly visual, mouse over the statement). type ExcludeFunctionAndSize2 = ConditionalSimplifyDeep; -expectType(movableNode); +expectTypeOf(movableNode).toEqualTypeOf(); diff --git a/test-d/delimiter-case.ts b/test-d/delimiter-case.ts index b5a2882a4..2de8bbd88 100644 --- a/test-d/delimiter-case.ts +++ b/test-d/delimiter-case.ts @@ -1,58 +1,58 @@ -import {expectType, expectAssignable} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {UpperCaseCharacters, WordSeparators} from '../source/internal'; import type {SplitIncludingDelimiters, DelimiterCase} from '../source/delimiter-case'; const splitFromCamel: SplitIncludingDelimiters<'fooBar', WordSeparators | UpperCaseCharacters> = ['foo', 'B', 'ar']; -expectType<['foo', 'B', 'ar']>(splitFromCamel); +expectTypeOf(splitFromCamel).toEqualTypeOf<['foo', 'B', 'ar']>(); const splitFromComplexCamel: SplitIncludingDelimiters<'fooBarAbc123', WordSeparators | UpperCaseCharacters> = ['foo', 'B', 'ar', 'A', 'bc123']; -expectType<['foo', 'B', 'ar', 'A', 'bc123']>(splitFromComplexCamel); +expectTypeOf(splitFromComplexCamel).toEqualTypeOf<['foo', 'B', 'ar', 'A', 'bc123']>(); const splitFromWordSeparators: SplitIncludingDelimiters<'foo-bar_car far', WordSeparators> = ['foo', '-', 'bar', '_', 'car', ' ', 'far']; -expectType<['foo', '-', 'bar', '_', 'car', ' ', 'far']>(splitFromWordSeparators); +expectTypeOf(splitFromWordSeparators).toEqualTypeOf<['foo', '-', 'bar', '_', 'car', ' ', 'far']>(); const splitFromScreamingSnakeCase: SplitIncludingDelimiters<'FOO_BAR', WordSeparators | UpperCaseCharacters> = ['foo', '_', 'bar']; -expectType<['foo', '_', 'bar']>(splitFromScreamingSnakeCase); +expectTypeOf(splitFromScreamingSnakeCase).toEqualTypeOf<['foo', '_', 'bar']>(); // DelimiterCase const delimiterFromCamel: DelimiterCase<'fooBar', '#'> = 'foo#bar'; -expectType<'foo#bar'>(delimiterFromCamel); +expectTypeOf(delimiterFromCamel).toEqualTypeOf<'foo#bar'>(); const delimiterFromComplexCamel: DelimiterCase<'fooBarAbc123', '#'> = 'foo#bar#abc123'; -expectType<'foo#bar#abc123'>(delimiterFromComplexCamel); +expectTypeOf(delimiterFromComplexCamel).toEqualTypeOf<'foo#bar#abc123'>(); const delimiterFromPascal: DelimiterCase<'FooBar', '#'> = 'foo#bar'; -expectType<'foo#bar'>(delimiterFromPascal); +expectTypeOf(delimiterFromPascal).toEqualTypeOf<'foo#bar'>(); const delimiterFromKebab: DelimiterCase<'foo-bar', '#'> = 'foo#bar'; -expectType<'foo#bar'>(delimiterFromKebab); +expectTypeOf(delimiterFromKebab).toEqualTypeOf<'foo#bar'>(); const delimiterFromComplexKebab: DelimiterCase<'foo-bar-abc-123', '#'> = 'foo#bar#abc#123'; -expectType<'foo#bar#abc#123'>(delimiterFromComplexKebab); +expectTypeOf(delimiterFromComplexKebab).toEqualTypeOf<'foo#bar#abc#123'>(); const delimiterFromSpace: DelimiterCase<'foo bar', '#'> = 'foo#bar'; -expectType<'foo#bar'>(delimiterFromSpace); +expectTypeOf(delimiterFromSpace).toEqualTypeOf<'foo#bar'>(); const delimiterFromSnake: DelimiterCase<'foo_bar', '#'> = 'foo#bar'; -expectType<'foo#bar'>(delimiterFromSnake); +expectTypeOf(delimiterFromSnake).toEqualTypeOf<'foo#bar'>(); const noDelimiterFromMono: DelimiterCase<'foobar', '#'> = 'foobar'; -expectType<'foobar'>(noDelimiterFromMono); +expectTypeOf(noDelimiterFromMono).toEqualTypeOf<'foobar'>(); const delimiterFromMixed: DelimiterCase<'foo-bar_abc xyzBarFoo', '#'> = 'foo#bar#abc#xyz#bar#foo'; -expectType<'foo#bar#abc#xyz#bar#foo'>(delimiterFromMixed); +expectTypeOf(delimiterFromMixed).toEqualTypeOf<'foo#bar#abc#xyz#bar#foo'>(); const delimiterFromVendorPrefixedCssProperty: DelimiterCase<'-webkit-animation', '#'> = '#webkit#animation'; -expectType<'#webkit#animation'>(delimiterFromVendorPrefixedCssProperty); +expectTypeOf(delimiterFromVendorPrefixedCssProperty).toEqualTypeOf<'#webkit#animation'>(); const delimiterFromDoublePrefixedKebab: DelimiterCase<'--very-prefixed', '#'> = '##very#prefixed'; -expectType<'##very#prefixed'>(delimiterFromDoublePrefixedKebab); +expectTypeOf(delimiterFromDoublePrefixedKebab).toEqualTypeOf<'##very#prefixed'>(); const delimiterFromRepeatedSeparators: DelimiterCase<'foo____bar', '#'> = 'foo####bar'; -expectType<'foo####bar'>(delimiterFromRepeatedSeparators); +expectTypeOf(delimiterFromRepeatedSeparators).toEqualTypeOf<'foo####bar'>(); const delimiterFromString: DelimiterCase = 'foobar'; -expectType(delimiterFromString); +expectTypeOf(delimiterFromString).toEqualTypeOf(); const delimiterFromScreamingSnake: DelimiterCase<'FOO_BAR', '#'> = 'foo#bar'; -expectType<'foo#bar'>(delimiterFromScreamingSnake); +expectTypeOf(delimiterFromScreamingSnake).toEqualTypeOf<'foo#bar'>(); // Verifying example type OddCasedProperties = { @@ -65,8 +65,8 @@ type CliOptions = { foo: number; }; -expectAssignable>({ +expectTypeOf({ 'dry#run': true, 'include#file': 'bar.js', foo: 123, -}); +}).toMatchTypeOf>(); diff --git a/test-d/delimiter-cased-properties-deep.ts b/test-d/delimiter-cased-properties-deep.ts index efa19586a..d75434409 100644 --- a/test-d/delimiter-cased-properties-deep.ts +++ b/test-d/delimiter-cased-properties-deep.ts @@ -1,14 +1,14 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {DelimiterCasedPropertiesDeep} from '../index'; declare const foo: DelimiterCasedPropertiesDeep<{helloWorld: {fooBar: string}}, '/'>; -expectType<{'hello/world': {'foo/bar': string}}>(foo); +expectTypeOf(foo).toEqualTypeOf<{'hello/world': {'foo/bar': string}}>(); declare const fooBar: DelimiterCasedPropertiesDeep<() => {a: string}, '/'>; -expectType<() => {a: string}>(fooBar); +expectTypeOf(fooBar).toEqualTypeOf<() => {a: string}>(); declare const bar: DelimiterCasedPropertiesDeep, '-'>; -expectType>(bar); +expectTypeOf(bar).toEqualTypeOf>(); // Verify example type User = { @@ -45,4 +45,4 @@ const result: DelimiterCasedPropertiesDeep = { }, ], }; -expectType>(result); +expectTypeOf(result).toEqualTypeOf>(); diff --git a/test-d/delimiter-cased-properties.ts b/test-d/delimiter-cased-properties.ts index 157aafe57..408639431 100644 --- a/test-d/delimiter-cased-properties.ts +++ b/test-d/delimiter-cased-properties.ts @@ -1,14 +1,14 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {DelimiterCasedProperties} from '../index'; declare const foo: DelimiterCasedProperties<{helloWorld: {fooBar: string}}, '/'>; -expectType<{'hello/world': {fooBar: string}}>(foo); +expectTypeOf(foo).toEqualTypeOf<{'hello/world': {fooBar: string}}>(); declare const bar: DelimiterCasedProperties, '-'>; -expectType>(bar); +expectTypeOf(bar).toEqualTypeOf>(); declare const fooBar: DelimiterCasedProperties<() => {a: string}, '-'>; -expectType<() => {a: string}>(fooBar); +expectTypeOf(fooBar).toEqualTypeOf<() => {a: string}>(); // Verify example type User = { @@ -19,4 +19,4 @@ const result: DelimiterCasedProperties = { 'user-id': 1, 'user-name': 'Tom', }; -expectType>(result); +expectTypeOf(result).toEqualTypeOf>(); diff --git a/test-d/empty-object.ts b/test-d/empty-object.ts index 14d5eeaa8..41e642098 100644 --- a/test-d/empty-object.ts +++ b/test-d/empty-object.ts @@ -1,29 +1,37 @@ -import {expectAssignable, expectError, expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {EmptyObject, IsEmptyObject} from '../index'; declare let foo: EmptyObject; -expectAssignable<{}>(foo); -expectAssignable<{}>(foo = {}); - -expectError(foo = []); -expectError(foo = {x: 1}); -expectError(foo = 42); -expectError(foo = null); -expectError(foo.bar = 42); -expectError(foo.bar = {}); - -expectType>(true); -expectType>(true); - -expectType>(false); -expectType>(false); -expectType void>>(false); +expectTypeOf(foo).toMatchTypeOf<{}>(); +expectTypeOf(foo = {}).toMatchTypeOf<{}>(); + +// @ts-expect-error +foo = []; +// @ts-expect-error +foo = {x: 1}; +// @ts-expect-error +foo = 42; +// @ts-expect-error +foo = null; +// @ts-expect-error +foo.bar = 42; +// @ts-expect-error +foo.bar = {}; + +expectTypeOf().toEqualTypeOf>(); +expectTypeOf().toEqualTypeOf>(); + +expectTypeOf().toEqualTypeOf>(); +expectTypeOf().toEqualTypeOf>(); +expectTypeOf().toEqualTypeOf void>>(); type Union = EmptyObject | {id: number}; const bar: Union = {}; -expectError(bar.id); +// @ts-expect-error +// eslint-disable-next-line @typescript-eslint/no-unused-expressions +bar.id; const baz: Union = {id: 42}; -expectType<{id: number}>(baz); +expectTypeOf(baz).toEqualTypeOf<{id: number}>(); diff --git a/test-d/enforce-optional.ts b/test-d/enforce-optional.ts index 1b008294d..81ae2a24d 100644 --- a/test-d/enforce-optional.ts +++ b/test-d/enforce-optional.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {EnforceOptional} from '../source/enforce-optional'; type Foo = { @@ -12,9 +12,9 @@ type EnforcedOptionalFoo = EnforceOptional; declare const enforcedOptionalFoo: EnforcedOptionalFoo; -expectType<{ +expectTypeOf(enforcedOptionalFoo).toEqualTypeOf<{ a: string; b?: string; c: undefined; d?: number; -}>(enforcedOptionalFoo); +}>(); diff --git a/test-d/entries.ts b/test-d/entries.ts index b8e09856f..f0f786b79 100644 --- a/test-d/entries.ts +++ b/test-d/entries.ts @@ -1,4 +1,4 @@ -import {expectAssignable} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {Entries} from '../index'; import type {Entry} from '../source/entry'; @@ -6,46 +6,46 @@ import type {Entry} from '../source/entry'; const objectExample = {a: 1}; const objectEntry: Entry = ['a', 1]; -expectAssignable<[string, number]>(objectEntry); +expectTypeOf(objectEntry).toMatchTypeOf<[string, number]>(); const objectEntries: Entries = [objectEntry]; -expectAssignable>(objectEntries); +expectTypeOf(objectEntries).toMatchTypeOf>(); // Maps const mapExample = new Map([['a', 1]]); const mapEntry: Entry = ['a', 1]; -expectAssignable<[string, number]>(mapEntry); +expectTypeOf(mapEntry).toMatchTypeOf<[string, number]>(); const mapEntries: Entries = [mapEntry]; -expectAssignable>(mapEntries); +expectTypeOf(mapEntries).toMatchTypeOf>(); // Arrays const arrayExample = ['a', 1]; const arrayEntryString: Entry = [0, 'a']; -expectAssignable<[number, (string | number)]>(arrayEntryString); +expectTypeOf(arrayEntryString).toMatchTypeOf<[number, (string | number)]>(); const arrayEntryNumber: Entry = [1, 1]; -expectAssignable<[number, (string | number)]>(arrayEntryNumber); +expectTypeOf(arrayEntryNumber).toMatchTypeOf<[number, (string | number)]>(); const arrayEntries: Entries = [ arrayEntryString, arrayEntryNumber, ]; -expectAssignable>(arrayEntries); +expectTypeOf(arrayEntries).toMatchTypeOf>(); // Sets const setExample = new Set(['a', 1]); const setEntryString: Entry = ['a', 'a']; -expectAssignable<[(string | number), (string | number)]>(setEntryString); +expectTypeOf(setEntryString).toMatchTypeOf<[(string | number), (string | number)]>(); const setEntryNumber: Entry = [1, 1]; -expectAssignable<[(string | number), (string | number)]>(setEntryNumber); +expectTypeOf(setEntryNumber).toMatchTypeOf<[(string | number), (string | number)]>(); const setEntries: Entries = [ setEntryString, setEntryNumber, ]; -expectAssignable>(setEntries); +expectTypeOf(setEntries).toMatchTypeOf>(); diff --git a/test-d/except.ts b/test-d/except.ts index c166e52f8..058775040 100644 --- a/test-d/except.ts +++ b/test-d/except.ts @@ -1,8 +1,8 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {Except} from '../index'; declare const except: Except<{a: number; b: string}, 'b'>; -expectType<{a: number}>(except); +expectTypeOf(except).toEqualTypeOf<{a: number}>(); // Generic properties type Example = { @@ -12,6 +12,6 @@ type Example = { }; const test: Except = {foo: 123, bar: 'asdf'}; -expectType(test.foo); +expectTypeOf(test.foo).toEqualTypeOf(); // eslint-disable-next-line @typescript-eslint/dot-notation -expectType(test['bar']); +expectTypeOf(test['bar']).toEqualTypeOf(); diff --git a/test-d/fixed-length-array.ts b/test-d/fixed-length-array.ts index a5a4c75c8..ec37bd242 100644 --- a/test-d/fixed-length-array.ts +++ b/test-d/fixed-length-array.ts @@ -1,11 +1,11 @@ -import {expectAssignable, expectNotAssignable} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {FixedLengthArray} from '../index'; type FixedToThreeStrings = FixedLengthArray; -expectAssignable(['a', 'b', 'c']); +expectTypeOf<['a', 'b', 'c']>().toMatchTypeOf(); -expectNotAssignable(['a', 'b', 123]); -expectNotAssignable(['a']); -expectNotAssignable(['a', 'b']); -expectNotAssignable(['a', 'b', 'c', 'd']); +expectTypeOf<['a', 'b', 123]>().not.toMatchTypeOf(); +expectTypeOf<['a']>().not.toMatchTypeOf(); +expectTypeOf<['a', 'b']>().not.toMatchTypeOf(); +expectTypeOf<['a', 'b', 'c', 'd']>().not.toMatchTypeOf(); diff --git a/test-d/has-optional-keys.ts b/test-d/has-optional-keys.ts index 9a5b12aad..4c78c952d 100644 --- a/test-d/has-optional-keys.ts +++ b/test-d/has-optional-keys.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {HasOptionalKeys} from '../index'; type TestType1 = { @@ -24,6 +24,6 @@ declare const test1: HasOptionalKeys1; declare const test2: HasOptionalKeys2; declare const test3: HasOptionalKeys3; -expectType(test1); -expectType(test2); -expectType(test3); +expectTypeOf(test1).toEqualTypeOf(); +expectTypeOf(test2).toEqualTypeOf(); +expectTypeOf(test3).toEqualTypeOf(); diff --git a/test-d/has-required-keys.ts b/test-d/has-required-keys.ts index d88b2a637..ab693941c 100644 --- a/test-d/has-required-keys.ts +++ b/test-d/has-required-keys.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {HasRequiredKeys} from '../index'; type TestType1 = { @@ -24,6 +24,6 @@ declare const test1: HasRequiredKeys1; declare const test2: HasRequiredKeys2; declare const test3: HasRequiredKeys3; -expectType(test1); -expectType(test2); -expectType(test3); +expectTypeOf(test1).toEqualTypeOf(); +expectTypeOf(test2).toEqualTypeOf(); +expectTypeOf(test3).toEqualTypeOf(); diff --git a/test-d/includes.ts b/test-d/includes.ts index e3d3b5de0..cf46e3a6f 100644 --- a/test-d/includes.ts +++ b/test-d/includes.ts @@ -1,15 +1,15 @@ -import {expectError, expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {Includes} from '../index'; const includesEmptyArray: Includes<[], 'abc'> = false; -expectType(includesEmptyArray); +expectTypeOf(includesEmptyArray).toEqualTypeOf(); const includesSingleItemArray: Includes<['colors'], 'colors'> = true; -expectType(includesSingleItemArray); +expectTypeOf(includesSingleItemArray).toEqualTypeOf(); const readonlyArray = ['a', 'b', 'c'] as const; const includesReadonlyArray: Includes = true; -expectType(includesReadonlyArray); +expectTypeOf(includesReadonlyArray).toEqualTypeOf(); const includesComplexMultiTypeArray: Includes<[ { @@ -21,35 +21,33 @@ const includesComplexMultiTypeArray: Includes<[ null, 'abcd', ], 'abc'> = false; -expectType(includesComplexMultiTypeArray); +expectTypeOf(includesComplexMultiTypeArray).toEqualTypeOf(); const noExtendsProblem: Includes<[boolean], true> = false; -expectType(noExtendsProblem); +expectTypeOf(noExtendsProblem).toEqualTypeOf(); const objectIncludes: Includes<[{}], {a: 1}> = false; -expectType(objectIncludes); +expectTypeOf(objectIncludes).toEqualTypeOf(); const objectIncludesPass: Includes<[{a: 1}], {a: 1}> = true; -expectType(objectIncludesPass); +expectTypeOf(objectIncludesPass).toEqualTypeOf(); const nullIncludesUndefined: Includes<[null], undefined> = false; -expectType(nullIncludesUndefined); +expectTypeOf(nullIncludesUndefined).toEqualTypeOf(); const nullIncludesNullPass: Includes<[null], null> = true; -expectType(nullIncludesNullPass); - -declare const anything: any; +expectTypeOf(nullIncludesNullPass).toEqualTypeOf(); // Verify that incorrect usage of `Includes` produces an error. -// Missing all generic parameters. -expectError(anything); +// @ts-expect-error +declare const missingAllParameters: Includes; -// Missing `Item` generic parameter. -expectError>(anything); +// @ts-expect-error +declare const missingItem: Includes<['my', 'array', 'has', 'stuff']>; -// Value generic parameter is a string not an array. -expectError>(anything); +// @ts-expect-error +declare const badValueTypeSring: Includes<'why a string?', 5>; -// Value generic parameter is an object not an array. -expectError>(anything); +// @ts-expect-error +declare const badValueTypeObject: Includes<{key: 'value'}, 7>; diff --git a/test-d/index.ts b/test-d/index.ts index 45faeb594..520d98a7a 100644 --- a/test-d/index.ts +++ b/test-d/index.ts @@ -1,19 +1,19 @@ -import {expectType, expectAssignable} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {ObservableLike} from '../index'; // eslint-disable-next-line no-use-extend-native/no-use-extend-native -expectAssignable(Symbol.observable); +expectTypeOf(Symbol.observable).toMatchTypeOf(); const observable = (null as any) as ObservableLike; const subscription = observable.subscribe({ next() {}, // eslint-disable-line @typescript-eslint/no-empty-function }); -expectType<{unsubscribe(): void}>(subscription); +expectTypeOf(subscription).toEqualTypeOf<{unsubscribe(): void}>(); observable.subscribe({ next(value) { - expectType(value); + expectTypeOf(value).toEqualTypeOf(); }, }); @@ -24,6 +24,6 @@ observable2.subscribe({ }); observable2.subscribe({ next(value) { - expectType(value); + expectTypeOf(value).toEqualTypeOf(); }, }); diff --git a/test-d/invariant-of.ts b/test-d/invariant-of.ts index d35e6fdac..91438a044 100644 --- a/test-d/invariant-of.ts +++ b/test-d/invariant-of.ts @@ -1,4 +1,4 @@ -import {expectAssignable, expectNotAssignable} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {InvariantOf} from '../index'; type FooBar = InvariantOf<{ @@ -17,10 +17,10 @@ const fooBar: FooBar = {foo: 123, bar: 'hello'} as FooBar; // eslint-disable-lin const fooBarBaz: FooBarBaz = {foo: 123, bar: 'hello', baz: true} as FooBarBaz; // eslint-disable-line @typescript-eslint/consistent-type-assertions // The invariantOf is assignable to Type. -expectAssignable<{ +expectTypeOf(fooBar).toMatchTypeOf<{ foo: number; bar: string; -}>(fooBar); +}>(); -expectNotAssignable(fooBar); // Invariance does not accept supertypes. -expectNotAssignable(fooBarBaz); // Invariance does not accept subtypes. +expectTypeOf(fooBar).not.toMatchTypeOf(); // Invariance does not accept supertypes. +expectTypeOf(fooBarBaz).not.toMatchTypeOf(); // Invariance does not accept subtypes. diff --git a/test-d/iterable-element.ts b/test-d/iterable-element.ts index 1d7be6b0c..7c2a90369 100644 --- a/test-d/iterable-element.ts +++ b/test-d/iterable-element.ts @@ -1,11 +1,9 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {IterableElement} from '../index'; -declare const iterableElement: IterableElement>; -expectType<1 | 'two'>(iterableElement); +expectTypeOf>>().toEqualTypeOf<1 | 'two'>(); -declare const iterableElementAsync: IterableElement>; -expectType(iterableElementAsync); +expectTypeOf>>().toEqualTypeOf(); function * secretGenerator() { yield 1; diff --git a/test-d/join.ts b/test-d/join.ts index f50477e35..774cae418 100644 --- a/test-d/join.ts +++ b/test-d/join.ts @@ -1,23 +1,23 @@ -import {expectNotAssignable, expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {Join} from '../index'; // General use. const generalTestVariantMixed: Join<['foo', 0, 'baz'], '.'> = 'foo.0.baz'; const generalTestVariantOnlyStrings: Join<['foo', 'bar', 'baz'], '.'> = 'foo.bar.baz'; const generalTestVariantOnlyNumbers: Join<[1, 2, 3], '.'> = '1.2.3'; -expectType<'foo.0.baz'>(generalTestVariantMixed); -expectType<'1.2.3'>(generalTestVariantOnlyNumbers); -expectType<'foo.bar.baz'>(generalTestVariantOnlyStrings); -expectNotAssignable<'foo'>(generalTestVariantOnlyStrings); -expectNotAssignable<'foo.bar'>(generalTestVariantOnlyStrings); -expectNotAssignable<'foo.bar.ham'>(generalTestVariantOnlyStrings); +expectTypeOf(generalTestVariantMixed).toEqualTypeOf<'foo.0.baz'>(); +expectTypeOf(generalTestVariantOnlyNumbers).toEqualTypeOf<'1.2.3'>(); +expectTypeOf(generalTestVariantOnlyStrings).toEqualTypeOf<'foo.bar.baz'>(); +expectTypeOf(generalTestVariantOnlyStrings).not.toMatchTypeOf<'foo'>(); +expectTypeOf(generalTestVariantOnlyStrings).not.toMatchTypeOf<'foo.bar'>(); +expectTypeOf(generalTestVariantOnlyStrings).not.toMatchTypeOf<'foo.bar.ham'>(); // Empty string delimiter. const emptyDelimiter: Join<['foo', 'bar', 'baz'], ''> = 'foobarbaz'; -expectType<'foobarbaz'>(emptyDelimiter); -expectNotAssignable<'foo.bar.baz'>(emptyDelimiter); +expectTypeOf(emptyDelimiter).toEqualTypeOf<'foobarbaz'>(); +expectTypeOf(emptyDelimiter).not.toMatchTypeOf<'foo.bar.baz'>(); // Empty input. const emptyInput: Join<[], '.'> = ''; -expectType<''>(emptyInput); -expectNotAssignable<'foo'>(emptyInput); +expectTypeOf(emptyInput).toEqualTypeOf<''>(); +expectTypeOf(emptyInput).not.toMatchTypeOf<'foo'>(); diff --git a/test-d/jsonify.ts b/test-d/jsonify.ts index db67a2293..af73b67f1 100644 --- a/test-d/jsonify.ts +++ b/test-d/jsonify.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/consistent-type-definitions */ // TODO: Convert the `interface`'s to `type`s. -import {expectAssignable, expectNotAssignable, expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {EmptyObject, Jsonify, JsonValue, NegativeInfinity, PositiveInfinity} from '..'; interface A { @@ -42,29 +42,28 @@ declare const y: Y; // Not assignable to JsonValue because it contains Date valu declare const z: Z; // Not assignable to JsonValue because undefined is not valid Json value declare const w: W; // Not assignable to JsonValue because a function is not valid Json value -expectAssignable(null); -expectAssignable(false); -expectAssignable(0); -expectAssignable(''); -expectAssignable([]); -expectAssignable({}); -expectAssignable([0]); -expectAssignable({a: 0}); -expectAssignable(a); -expectAssignable(b); -expectAssignable({a: {b: true, c: {}}, d: [{}, 2, 'hi']}); -expectAssignable([{}, {a: 'hi'}, null, 3]); - -expectNotAssignable(new Date()); -expectNotAssignable([new Date()]); -expectNotAssignable({a: new Date()}); -expectNotAssignable(v); -expectNotAssignable(x); -expectNotAssignable(y); -expectNotAssignable(z); -expectNotAssignable(w); -expectNotAssignable(undefined); -expectNotAssignable(5 as number | undefined); +expectTypeOf().toMatchTypeOf(); +expectTypeOf().toMatchTypeOf(); +expectTypeOf<0>().toMatchTypeOf(); +expectTypeOf<''>().toMatchTypeOf(); +expectTypeOf<[]>().toMatchTypeOf(); +expectTypeOf<{}>().toMatchTypeOf(); +expectTypeOf<[0]>().toMatchTypeOf(); +expectTypeOf<{a: 0}>().toMatchTypeOf(); +expectTypeOf(a).toMatchTypeOf(); +expectTypeOf(b).toMatchTypeOf(); +expectTypeOf<{a: {b: true; c: {}}; d: [{}, 2, 'hi']}>().toMatchTypeOf(); +expectTypeOf<[{}, {a: 'hi'}, null, 3]>().toMatchTypeOf(); + +expectTypeOf(new Date()).not.toMatchTypeOf(); +expectTypeOf([new Date()]).not.toMatchTypeOf(); +expectTypeOf({a: new Date()}).not.toMatchTypeOf(); +expectTypeOf(v).not.toMatchTypeOf(); +expectTypeOf(x).not.toMatchTypeOf(); +expectTypeOf(y).not.toMatchTypeOf(); +expectTypeOf(z).not.toMatchTypeOf(); +expectTypeOf(w).not.toMatchTypeOf(); +expectTypeOf().not.toMatchTypeOf(); // TODO: Convert this to a `type`. interface Geometry { @@ -77,14 +76,14 @@ const point: Geometry = { coordinates: [1, 1], }; -expectNotAssignable(point); -expectAssignable>(point); +expectTypeOf(point).not.toMatchTypeOf(); +expectTypeOf(point).toMatchTypeOf>(); // The following const values are examples of values `v` that are not JSON, but are *jsonable* using // `v.toJSON()` or `JSON.parse(JSON.stringify(v))` declare const dateToJSON: Jsonify; -expectAssignable(dateToJSON); -expectAssignable(dateToJSON); +expectTypeOf(dateToJSON).toMatchTypeOf(); +expectTypeOf(dateToJSON).toMatchTypeOf(); // The following commented `= JSON.parse(JSON.stringify(x))` is an example of how `parsedStringifiedX` could be created. // * Note that this would be an unsafe assignment because `JSON.parse()` returns type `any`. @@ -93,8 +92,8 @@ expectAssignable(dateToJSON); // or an `as Jsonify` is added. // * This test is not about how `parsedStringifiedX` is created, but about its type, so the `const` value is declared. declare const parsedStringifiedX: Jsonify; // = JSON.parse(JSON.stringify(x)); -expectAssignable(parsedStringifiedX); -expectAssignable(parsedStringifiedX.a); +expectTypeOf(parsedStringifiedX).toMatchTypeOf(); +expectTypeOf(parsedStringifiedX.a).toMatchTypeOf(); class NonJsonWithToJSON { public fixture = new Map([['a', 1], ['b', 2]]); @@ -107,9 +106,9 @@ class NonJsonWithToJSON { } const nonJsonWithToJSON = new NonJsonWithToJSON(); -expectNotAssignable(nonJsonWithToJSON); -expectAssignable(nonJsonWithToJSON.toJSON()); -expectAssignable>(nonJsonWithToJSON.toJSON()); +expectTypeOf(nonJsonWithToJSON).not.toMatchTypeOf(); +expectTypeOf(nonJsonWithToJSON.toJSON()).toMatchTypeOf(); +expectTypeOf(nonJsonWithToJSON.toJSON()).toMatchTypeOf>(); class NonJsonWithToJSONWrapper { public inner: NonJsonWithToJSON = nonJsonWithToJSON; @@ -126,15 +125,15 @@ class NonJsonWithToJSONWrapper { } } -expectNotAssignable(new NonJsonWithToJSONWrapper()); +expectTypeOf(new NonJsonWithToJSONWrapper()).not.toMatchTypeOf(); type InnerFixture = {fixture: Array<[string, number]>}; -expectType<{ +expectTypeOf({} as Jsonify).toEqualTypeOf<{ override: string; inner: InnerFixture; innerDeep: {inner: InnerFixture}; -}>({} as Jsonify); +}>(); class NonJsonWithInvalidToJSON { public fixture = new Map([['a', 1], ['b', 2]]); @@ -149,112 +148,112 @@ class NonJsonWithInvalidToJSON { } const nonJsonWithInvalidToJSON = new NonJsonWithInvalidToJSON(); -expectNotAssignable(nonJsonWithInvalidToJSON); -expectNotAssignable(nonJsonWithInvalidToJSON.toJSON()); +expectTypeOf(nonJsonWithInvalidToJSON).not.toMatchTypeOf(); +expectTypeOf(nonJsonWithInvalidToJSON.toJSON()).not.toMatchTypeOf(); // Not jsonable types; these types behave differently when used as plain values, as members of arrays and as values of objects declare const undefined: undefined; -expectNotAssignable(undefined); +expectTypeOf().not.toMatchTypeOf(); declare const fn: (_: any) => void; -expectNotAssignable(fn); +expectTypeOf(fn).not.toMatchTypeOf(); declare const symbol: symbol; -expectNotAssignable(symbol); +expectTypeOf(symbol).not.toMatchTypeOf(); // Plain values fail JSON.stringify() declare const plainUndefined: Jsonify; -expectType(plainUndefined); +expectTypeOf(plainUndefined).toEqualTypeOf(); declare const plainFn: Jsonify; -expectType(plainFn); +expectTypeOf(plainFn).toEqualTypeOf(); declare const plainSymbol: Jsonify; -expectType(plainSymbol); +expectTypeOf(plainSymbol).toEqualTypeOf(); // Array members become null declare const arrayMemberUndefined: Jsonify>; -expectType(arrayMemberUndefined); +expectTypeOf(arrayMemberUndefined).toEqualTypeOf(); declare const arrayMemberFn: Jsonify>; -expectType(arrayMemberFn); +expectTypeOf(arrayMemberFn).toEqualTypeOf(); declare const arrayMemberSymbol: Jsonify>; -expectType(arrayMemberSymbol); +expectTypeOf(arrayMemberSymbol).toEqualTypeOf(); // When used in object values, these keys are filtered declare const objectValueUndefined: Jsonify<{keep: string; undefined: typeof undefined}>; -expectType<{keep: string}>(objectValueUndefined); +expectTypeOf(objectValueUndefined).toEqualTypeOf<{keep: string}>(); declare const objectValueFn: Jsonify<{keep: string; fn: typeof fn}>; -expectType<{keep: string}>(objectValueFn); +expectTypeOf(objectValueFn).toEqualTypeOf<{keep: string}>(); declare const objectValueSymbol: Jsonify<{keep: string; symbol: typeof symbol}>; -expectType<{keep: string}>(objectValueSymbol); +expectTypeOf(objectValueSymbol).toEqualTypeOf<{keep: string}>(); // Symbol keys are filtered declare const objectKeySymbol: Jsonify<{[key: typeof symbol]: number; keep: string}>; -expectType<{keep: string}>(objectKeySymbol); +expectTypeOf(objectKeySymbol).toEqualTypeOf<{keep: string}>(); // Number, String and Boolean values are turned into primitive counterparts declare const number: Number; -expectNotAssignable(number); +expectTypeOf(number).not.toMatchTypeOf(); declare const string: String; -expectNotAssignable(string); +expectTypeOf(string).not.toMatchTypeOf(); declare const boolean: Boolean; -expectNotAssignable(boolean); +expectTypeOf(boolean).not.toMatchTypeOf(); declare const numberJson: Jsonify; -expectType(numberJson); +expectTypeOf(numberJson).toEqualTypeOf(); declare const stringJson: Jsonify; -expectType(stringJson); +expectTypeOf(stringJson).toEqualTypeOf(); declare const booleanJson: Jsonify; -expectType(booleanJson); +expectTypeOf(booleanJson).toEqualTypeOf(); declare const tupleJson: Jsonify<[string, Date]>; -expectType<[string, string]>(tupleJson); +expectTypeOf(tupleJson).toEqualTypeOf<[string, string]>(); declare const tupleRestJson: Jsonify<[string, ...Date[]]>; -expectType<[string, ...string[]]>(tupleRestJson); +expectTypeOf(tupleRestJson).toEqualTypeOf<[string, ...string[]]>(); // BigInt fails JSON.stringify declare const bigInt: Jsonify; -expectType(bigInt); +expectTypeOf(bigInt).toEqualTypeOf(); declare const int8Array: Int8Array; declare const int8ArrayJson: Jsonify; -expectType>(int8ArrayJson); +expectTypeOf(int8ArrayJson).toEqualTypeOf>(); declare const map: Map; declare const mapJson: Jsonify; -expectType(mapJson); -expectAssignable>({}); +expectTypeOf(mapJson).toEqualTypeOf(); +expectTypeOf<{}>().toMatchTypeOf>(); // Regression test for https://github.com/sindresorhus/type-fest/issues/466 -expectNotAssignable>(42); -expectNotAssignable>({foo: 42}); +expectTypeOf<42>().not.toMatchTypeOf>(); +expectTypeOf<{foo: 42}>().not.toMatchTypeOf>(); declare const set: Set; declare const setJson: Jsonify; -expectType(setJson); -expectAssignable>({}); +expectTypeOf(setJson).toEqualTypeOf(); +expectTypeOf<{}>().toMatchTypeOf>(); // Regression test for https://github.com/sindresorhus/type-fest/issues/466 -expectNotAssignable>(42); -expectNotAssignable>({foo: 42}); +expectTypeOf<42>().not.toMatchTypeOf>(); +expectTypeOf<{foo: 42}>().not.toMatchTypeOf>(); // Positive and negative Infinity, NaN and null are turned into null // NOTE: NaN is not detectable in TypeScript, so it is not tested; see https://github.com/sindresorhus/type-fest/issues/406 declare const positiveInfinity: PositiveInfinity; declare const positiveInfJson: Jsonify; -expectType(positiveInfJson); +expectTypeOf(positiveInfJson).toEqualTypeOf(); declare const negativeInf: NegativeInfinity; declare const negativeInfJson: Jsonify; -expectType(negativeInfJson); +expectTypeOf(negativeInfJson).toEqualTypeOf(); // Test that optional type members are not discarded wholesale. type OptionalPrimitive = { @@ -273,9 +272,9 @@ declare const jsonifiedOptionalPrimitive: Jsonify; declare const jsonifiedOptionalTypeUnion: Jsonify; declare const jsonifiedNonOptionalTypeUnion: Jsonify; -expectType<{a?: string}>(jsonifiedOptionalPrimitive); -expectType<{}>(jsonifiedOptionalTypeUnion); -expectType<{a?: string}>(jsonifiedNonOptionalTypeUnion); +expectTypeOf(jsonifiedOptionalPrimitive).toEqualTypeOf<{a?: string}>(); +expectTypeOf(jsonifiedOptionalTypeUnion).toEqualTypeOf<{}>(); +expectTypeOf(jsonifiedNonOptionalTypeUnion).toEqualTypeOf<{a?: string}>(); // Test for 'Jsonify support for optional object keys, unserializable object values' #424 // See https://github.com/sindresorhus/type-fest/issues/424 @@ -311,4 +310,4 @@ type ExpectedAppDataJson = { declare const response: Jsonify; -expectType(response); +expectTypeOf(response).toEqualTypeOf(); diff --git a/test-d/kebab-case.ts b/test-d/kebab-case.ts index b200625c3..b78d4e2ce 100644 --- a/test-d/kebab-case.ts +++ b/test-d/kebab-case.ts @@ -1,17 +1,17 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {KebabCase} from '../index'; const kebabFromCamel: KebabCase<'fooBar'> = 'foo-bar'; -expectType<'foo-bar'>(kebabFromCamel); +expectTypeOf(kebabFromCamel).toEqualTypeOf<'foo-bar'>(); const kebabFromKebab: KebabCase<'foo-bar'> = 'foo-bar'; -expectType<'foo-bar'>(kebabFromKebab); +expectTypeOf(kebabFromKebab).toEqualTypeOf<'foo-bar'>(); const kebabFromSpace: KebabCase<'foo bar'> = 'foo-bar'; -expectType<'foo-bar'>(kebabFromSpace); +expectTypeOf(kebabFromSpace).toEqualTypeOf<'foo-bar'>(); const kebabFromSnake: KebabCase<'foo_bar'> = 'foo-bar'; -expectType<'foo-bar'>(kebabFromSnake); +expectTypeOf(kebabFromSnake).toEqualTypeOf<'foo-bar'>(); const noKebabFromMono: KebabCase<'foobar'> = 'foobar'; -expectType<'foobar'>(noKebabFromMono); +expectTypeOf(noKebabFromMono).toEqualTypeOf<'foobar'>(); diff --git a/test-d/kebab-cased-properties-deep.ts b/test-d/kebab-cased-properties-deep.ts index 64e18cd10..fa9a28e5b 100644 --- a/test-d/kebab-cased-properties-deep.ts +++ b/test-d/kebab-cased-properties-deep.ts @@ -1,11 +1,11 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {KebabCasedPropertiesDeep} from '../index'; declare const foo: KebabCasedPropertiesDeep<{helloWorld: {fooBar: string}}>; -expectType<{'hello-world': {'foo-bar': string}}>(foo); +expectTypeOf(foo).toEqualTypeOf<{'hello-world': {'foo-bar': string}}>(); declare const bar: KebabCasedPropertiesDeep>; -expectType>(bar); +expectTypeOf(bar).toEqualTypeOf>(); // Verify example type User = { @@ -42,4 +42,4 @@ const result: KebabCasedPropertiesDeep = { }, ], }; -expectType>(result); +expectTypeOf(result).toEqualTypeOf>(); diff --git a/test-d/kebab-cased-properties.ts b/test-d/kebab-cased-properties.ts index 775335fc4..32d7e40c7 100644 --- a/test-d/kebab-cased-properties.ts +++ b/test-d/kebab-cased-properties.ts @@ -1,8 +1,8 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {KebabCasedProperties} from '../index'; declare const foo: KebabCasedProperties<{helloWorld: {fooBar: string}}>; -expectType<{'hello-world': {fooBar: string}}>(foo); +expectTypeOf(foo).toEqualTypeOf<{'hello-world': {fooBar: string}}>(); // Verify example type User = { @@ -13,4 +13,4 @@ const result: KebabCasedProperties = { 'user-id': 1, 'user-name': 'Tom', }; -expectType>(result); +expectTypeOf(result).toEqualTypeOf>(); diff --git a/test-d/last-array-element.ts b/test-d/last-array-element.ts index 9eb2b1b1d..f6e36802d 100644 --- a/test-d/last-array-element.ts +++ b/test-d/last-array-element.ts @@ -1,12 +1,12 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {LastArrayElement} from '../index'; declare function lastOf(array: V): LastArrayElement; const array: ['foo', 2, 'bar'] = ['foo', 2, 'bar']; const mixedArray: ['bar', 'foo', 2] = ['bar', 'foo', 2]; -expectType<'bar'>(lastOf(array)); -expectType<2>(lastOf(mixedArray)); -expectType(lastOf(['a', 'b', 'c'])); -expectType(lastOf(['a', 'b', 1])); -expectType<1>(lastOf(['a', 'b', 1] as const)); +expectTypeOf(lastOf(array)).toEqualTypeOf<'bar'>(); +expectTypeOf(lastOf(mixedArray)).toEqualTypeOf<2>(); +expectTypeOf(lastOf(['a', 'b', 'c'])).toEqualTypeOf(); +expectTypeOf(lastOf(['a', 'b', 1])).toEqualTypeOf(); +expectTypeOf(lastOf(['a', 'b', 1] as const)).toEqualTypeOf<1>(); diff --git a/test-d/literal-to-primitive.ts b/test-d/literal-to-primitive.ts index ec4e8c621..9d9e84845 100644 --- a/test-d/literal-to-primitive.ts +++ b/test-d/literal-to-primitive.ts @@ -1,12 +1,12 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {LiteralToPrimitive} from '../index'; // Simple usage declare const numberPrimitive: LiteralToPrimitive<123>; -expectType(numberPrimitive); +expectTypeOf(numberPrimitive).toEqualTypeOf(); const symbol = Symbol('foo'); // Union declare const kitchenSink: LiteralToPrimitive<123 | 123n | 'hello' | true | undefined | typeof symbol | null | {key: string}>; -expectType(kitchenSink); +expectTypeOf(kitchenSink).toEqualTypeOf(); diff --git a/test-d/merge-deep.ts b/test-d/merge-deep.ts index c69acbe2d..131f0667b 100644 --- a/test-d/merge-deep.ts +++ b/test-d/merge-deep.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {MergeDeep, MergeDeepOptions} from '../index'; // Test helper. @@ -9,74 +9,74 @@ declare function mergeDeep< >(destination: Destination, source: Source, options?: Options): MergeDeep; // Test valid signatures for objects. -expectType<{}>(mergeDeep({}, {})); -expectType<{}>(mergeDeep({} as const, {})); -expectType<{}>(mergeDeep({}, {} as const)); -expectType<{}>(mergeDeep({} as const, {} as const)); +expectTypeOf(mergeDeep({}, {})).toEqualTypeOf<{}>(); +expectTypeOf(mergeDeep({} as const, {})).toEqualTypeOf<{}>(); +expectTypeOf(mergeDeep({}, {} as const)).toEqualTypeOf<{}>(); +expectTypeOf(mergeDeep({} as const, {} as const)).toEqualTypeOf<{}>(); // Test valid signatures for arrays/tuples. -expectType(mergeDeep([], [])); -expectType(mergeDeep([] as const, [])); -expectType(mergeDeep([], [] as const)); -expectType(mergeDeep([] as const, [] as const)); +expectTypeOf(mergeDeep([], [])).toEqualTypeOf(); +expectTypeOf(mergeDeep([] as const, [])).toEqualTypeOf(); +expectTypeOf(mergeDeep([], [] as const)).toEqualTypeOf(); +expectTypeOf(mergeDeep([] as const, [] as const)).toEqualTypeOf(); // Test invalid signatures. -expectType(mergeDeep({}, [])); -expectType(mergeDeep([], {})); -expectType(mergeDeep(null, {})); -expectType(mergeDeep([], 'life')); -expectType(mergeDeep([], new Set())); -expectType(mergeDeep(new Set(), new Set())); -expectType(mergeDeep(undefined, undefined)); -expectType(mergeDeep({}, undefined)); -expectType(mergeDeep(undefined, {})); +expectTypeOf(mergeDeep({}, [])).toEqualTypeOf(); +expectTypeOf(mergeDeep([], {})).toEqualTypeOf(); +expectTypeOf(mergeDeep(null, {})).toEqualTypeOf(); +expectTypeOf(mergeDeep([], 'life')).toEqualTypeOf(); +expectTypeOf(mergeDeep([], new Set())).toEqualTypeOf(); +expectTypeOf(mergeDeep(new Set(), new Set())).toEqualTypeOf(); +expectTypeOf(mergeDeep(undefined, undefined)).toEqualTypeOf(); +expectTypeOf(mergeDeep({}, undefined)).toEqualTypeOf(); +expectTypeOf(mergeDeep(undefined, {})).toEqualTypeOf(); // Should merge simple objects -expectType<{a: string; b: number}>(mergeDeep({a: 'life'}, {b: 42})); -expectType<{a: 'life'; b: number}>(mergeDeep({a: 'life'} as const, {b: 42})); -expectType<{a: string; b: 42}>(mergeDeep({a: 'life'}, {b: 42} as const)); -expectType<{a: 'life'; b: 42}>(mergeDeep({a: 'life'} as const, {b: 42} as const)); +expectTypeOf(mergeDeep({a: 'life'}, {b: 42})).toEqualTypeOf<{a: string; b: number}>(); +expectTypeOf(mergeDeep({a: 'life'} as const, {b: 42})).toEqualTypeOf<{a: 'life'; b: number}>(); +expectTypeOf(mergeDeep({a: 'life'}, {b: 42} as const)).toEqualTypeOf<{a: string; b: 42}>(); +expectTypeOf(mergeDeep({a: 'life'} as const, {b: 42} as const)).toEqualTypeOf<{a: 'life'; b: 42}>(); // Should spread simple arrays/tuples (default mode) -expectType>(mergeDeep(['life'], [42])); -expectType>(mergeDeep(['life'] as const, [42])); -expectType>(mergeDeep(['life'], [42] as const)); -expectType>(mergeDeep(['life'] as const, [42] as const)); +expectTypeOf(mergeDeep(['life'], [42])).toEqualTypeOf>(); +expectTypeOf(mergeDeep(['life'] as const, [42])).toEqualTypeOf>(); +expectTypeOf(mergeDeep(['life'], [42] as const)).toEqualTypeOf>(); +expectTypeOf(mergeDeep(['life'] as const, [42] as const)).toEqualTypeOf>(); -expectType>(mergeDeep(['life'], [42], {arrayMergeMode: 'spread'})); -expectType>(mergeDeep(['life'] as const, [42], {arrayMergeMode: 'spread'})); -expectType>(mergeDeep(['life'], [42] as const, {arrayMergeMode: 'spread'})); -expectType>(mergeDeep(['life'] as const, [42] as const, {arrayMergeMode: 'spread'})); +expectTypeOf(mergeDeep(['life'], [42], {arrayMergeMode: 'spread'})).toEqualTypeOf>(); +expectTypeOf(mergeDeep(['life'] as const, [42], {arrayMergeMode: 'spread'})).toEqualTypeOf>(); +expectTypeOf(mergeDeep(['life'], [42] as const, {arrayMergeMode: 'spread'})).toEqualTypeOf>(); +expectTypeOf(mergeDeep(['life'] as const, [42] as const, {arrayMergeMode: 'spread'})).toEqualTypeOf>(); // Should replace simple arrays/tuples -expectType>(mergeDeep(['life'], [42], {arrayMergeMode: 'replace'})); -expectType>(mergeDeep(['life'] as const, [42], {arrayMergeMode: 'replace'})); -expectType>(mergeDeep(['life'], [42] as const, {arrayMergeMode: 'replace'})); -expectType>(mergeDeep(['life'] as const, [42] as const, {arrayMergeMode: 'replace'})); +expectTypeOf(mergeDeep(['life'], [42], {arrayMergeMode: 'replace'})).toEqualTypeOf>(); +expectTypeOf(mergeDeep(['life'] as const, [42], {arrayMergeMode: 'replace'})).toEqualTypeOf>(); +expectTypeOf(mergeDeep(['life'], [42] as const, {arrayMergeMode: 'replace'})).toEqualTypeOf>(); +expectTypeOf(mergeDeep(['life'] as const, [42] as const, {arrayMergeMode: 'replace'})).toEqualTypeOf>(); // Should merge tuples with union -expectType>(mergeDeep(['life', true], [42], {arrayMergeMode: 'spread'})); -expectType>(mergeDeep(['life'], [42, true], {arrayMergeMode: 'spread'})); +expectTypeOf(mergeDeep(['life', true], [42], {arrayMergeMode: 'spread'})).toEqualTypeOf>(); +expectTypeOf(mergeDeep(['life'], [42, true], {arrayMergeMode: 'spread'})).toEqualTypeOf>(); // Should merge simple types type Foo = {foo: string; fooBar: unknown; items: string[]}; type Bar = {bar: number; fooBar: boolean; items: number[]}; declare const fooBar: MergeDeep; -expectType<{foo: string; bar: number; fooBar: boolean; items: number[]}>(fooBar); +expectTypeOf(fooBar).toEqualTypeOf<{foo: string; bar: number; fooBar: boolean; items: number[]}>(); declare const fooBarSpread: MergeDeep; -expectType<{foo: string; bar: number; fooBar: boolean; items: Array}>(fooBarSpread); +expectTypeOf(fooBarSpread).toEqualTypeOf<{foo: string; bar: number; fooBar: boolean; items: Array}>(); declare const fooBarReplace: MergeDeep; -expectType<{foo: string; bar: number; fooBar: boolean; items: number[]}>(fooBarReplace); +expectTypeOf(fooBarReplace).toEqualTypeOf<{foo: string; bar: number; fooBar: boolean; items: number[]}>(); // Should merge types deep type FooDeep = {foo: Foo; fooBar: Foo; items: {foo: Foo[]; fooBar: Foo}}; type BarDeep = {bar: Bar; fooBar: Bar; items: {bar: Bar[]; fooBar: Bar}}; declare const fooBarDeep: MergeDeep; -expectType<{ +expectTypeOf(fooBarDeep).toEqualTypeOf<{ foo: { foo: string; fooBar: unknown; @@ -103,7 +103,7 @@ expectType<{ items: number[]; }; }; -}>(fooBarDeep); +}>(); // Should merge types with index signatures deep type FooWithIndexSignature = {[x: number]: number; foo: string; items: string[]}; @@ -112,7 +112,7 @@ type FooWithIndexSignatureDeep = {[x: number]: number; foo: string; fooBar: FooW type BarWithIndexSignatureDeep = {[x: symbol]: symbol; bar: number; fooBar: BarWithIndexSignature; items: number[]}; declare const fooBarWithIndexSignature: MergeDeep; -expectType<{ +expectTypeOf(fooBarWithIndexSignature).toEqualTypeOf<{ [x: number]: number; [x: symbol]: symbol; foo: string; @@ -125,14 +125,14 @@ expectType<{ items: number[]; }; items: number[]; -}>(fooBarWithIndexSignature); +}>(); // Should merge types with optional properties deep type FooWithOptional = {foo: string; fooOptional?: string; fooBar: Foo; fooBarOptional: Foo | undefined}; type BarWithOptional = {bar: number; barOptional?: number; fooBar: Bar; fooBarOptional: Bar | undefined}; declare const fooBarWithOptional: MergeDeep; -expectType<{ +expectTypeOf(fooBarWithOptional).toEqualTypeOf<{ foo: string; bar: number; fooOptional?: string; @@ -149,53 +149,53 @@ expectType<{ fooBar: boolean; items: number[]; }; -}>(fooBarWithOptional); +}>(); // Should merge arrays with object entries type FooArray = Foo[]; type BarArray = Bar[]; declare const fooBarArray: MergeDeep; -expectType>(fooBarArray); +expectTypeOf(fooBarArray).toEqualTypeOf>(); declare const fooBarArraySpread: MergeDeep; -expectType>(fooBarArraySpread); +expectTypeOf(fooBarArraySpread).toEqualTypeOf>(); declare const fooBarArrayReplace: MergeDeep; -expectType>(fooBarArrayReplace); +expectTypeOf(fooBarArrayReplace).toEqualTypeOf>(); declare const fooBarArraySpreadRecursive: MergeDeep; -expectType; -}>>(fooBarArraySpreadRecursive); +}>>(); declare const fooBarArrayReplaceRecursive: MergeDeep; -expectType>(fooBarArrayReplaceRecursive); +}>>(); declare const fooBarArraySpreadRecursiveFallback: MergeDeep; -expectType>(fooBarArraySpreadRecursiveFallback); +expectTypeOf(fooBarArraySpreadRecursiveFallback).toEqualTypeOf>(); declare const fooBarArrayReplaceRecursiveFallback: MergeDeep; -expectType>(fooBarArrayReplaceRecursiveFallback); +expectTypeOf(fooBarArrayReplaceRecursiveFallback).toEqualTypeOf>(); declare const fooBarArrayDeepUnionRecursive: MergeDeep; -expectType; -}>>>>(fooBarArrayDeepUnionRecursive); +}>>>>(); declare const fooBarArrayDeepUnionRecursiveFallback: MergeDeep; -expectType>>(fooBarArrayDeepUnionRecursiveFallback); +expectTypeOf(fooBarArrayDeepUnionRecursiveFallback).toEqualTypeOf>>(); // Should merge tuples with object entries type FooTuple = [Foo, [Foo[], 42], 'foo']; @@ -205,54 +205,54 @@ type FooBarSpread = typeof fooBarSpread; type FooBarReplace = typeof fooBarReplace; declare const fooBarTupleSpread: MergeDeep; -expectType<[FooBarSpread, [FooBarSpread[], 'a', 'b'], 'bar', true]>(fooBarTupleSpread); +expectTypeOf(fooBarTupleSpread).toEqualTypeOf<[FooBarSpread, [FooBarSpread[], 'a', 'b'], 'bar', true]>(); declare const fooBarTupleReplace: MergeDeep; -expectType<[FooBarReplace, [FooBarReplace[], 'a', 'b'], 'bar', true]>(fooBarTupleReplace); +expectTypeOf(fooBarTupleReplace).toEqualTypeOf<[FooBarReplace, [FooBarReplace[], 'a', 'b'], 'bar', true]>(); // Should merge array into tuple with object entries type FooNumberTuple = [Foo[], number[]]; type BarArray2D = Bar[][]; declare const fooNumberTupleBarArray2DSpread: MergeDeep; -expectType<[FooBarSpread[], Array, ...BarArray2D]>(fooNumberTupleBarArray2DSpread); +expectTypeOf(fooNumberTupleBarArray2DSpread).toEqualTypeOf<[FooBarSpread[], Array, ...BarArray2D]>(); declare const fooNumberTupleBarArray2DReplace: MergeDeep; -expectType<[FooBarReplace[], Bar[], ...BarArray2D]>(fooNumberTupleBarArray2DReplace); +expectTypeOf(fooNumberTupleBarArray2DReplace).toEqualTypeOf<[FooBarReplace[], Bar[], ...BarArray2D]>(); // Should merge tuple into array with object entries type FooArray2D = Foo[][]; type BarNumberTuple = [Bar[], number[]]; declare const fooArray2DBarNumberTupleSpread: MergeDeep; -expectType<[FooBarSpread[], Array, ...FooArray2D]>(fooArray2DBarNumberTupleSpread); +expectTypeOf(fooArray2DBarNumberTupleSpread).toEqualTypeOf<[FooBarSpread[], Array, ...FooArray2D]>(); declare const fooArray2DBarNumberTupleReplace: MergeDeep; -expectType<[FooBarReplace[], number[], ...FooArray2D]>(fooArray2DBarNumberTupleReplace); +expectTypeOf(fooArray2DBarNumberTupleReplace).toEqualTypeOf<[FooBarReplace[], number[], ...FooArray2D]>(); // Should merge array into tuple with object entries and variadic length declare const arrayIntoTupleWithVariadicSpread: MergeDeep<[number, Foo, ...Foo[]], Bar[], {arrayMergeMode: 'spread'; recurseIntoArrays: true}>; -expectType<[Bar, FooBarSpread, ...FooBarSpread[]]>(arrayIntoTupleWithVariadicSpread); +expectTypeOf(arrayIntoTupleWithVariadicSpread).toEqualTypeOf<[Bar, FooBarSpread, ...FooBarSpread[]]>(); declare const arrayIntoTupleWithVariadicReplace: MergeDeep<[number, Foo, ...Foo[]], Bar[], {arrayMergeMode: 'replace'; recurseIntoArrays: true}>; -expectType<[Bar, FooBarReplace, ...FooBarReplace[]]>(arrayIntoTupleWithVariadicReplace); +expectTypeOf(arrayIntoTupleWithVariadicReplace).toEqualTypeOf<[Bar, FooBarReplace, ...FooBarReplace[]]>(); // Should merge tuple into array with object entries and variadic length declare const tupleIntoArrayWithVariadicSpread: MergeDeep; -expectType<[number, FooBarSpread, ...FooBarSpread[]]>(tupleIntoArrayWithVariadicSpread); +expectTypeOf(tupleIntoArrayWithVariadicSpread).toEqualTypeOf<[number, FooBarSpread, ...FooBarSpread[]]>(); declare const tupleIntoArrayWithVariadicReplace: MergeDeep; -expectType<[number, FooBarReplace, ...FooBarReplace[]]>(tupleIntoArrayWithVariadicReplace); +expectTypeOf(tupleIntoArrayWithVariadicReplace).toEqualTypeOf<[number, FooBarReplace, ...FooBarReplace[]]>(); // Should merge tuple into tuple with object entries and variadic length declare const tupleIntoTupleWithVariadicSpread: MergeDeep<[number, ...Foo[]], [Bar, Bar, ...Bar[]], {arrayMergeMode: 'spread'; recurseIntoArrays: true}>; -expectType<[Bar, FooBarSpread, ...FooBarSpread[]]>(tupleIntoTupleWithVariadicSpread); +expectTypeOf(tupleIntoTupleWithVariadicSpread).toEqualTypeOf<[Bar, FooBarSpread, ...FooBarSpread[]]>(); declare const tupleIntoTupleWithVariadicSpreadReversed: MergeDeep<[Foo, ...Foo[]], [number, Bar, ...Bar[]], {arrayMergeMode: 'spread'; recurseIntoArrays: true}>; -expectType<[number, FooBarSpread, ...FooBarSpread[]]>(tupleIntoTupleWithVariadicSpreadReversed); +expectTypeOf(tupleIntoTupleWithVariadicSpreadReversed).toEqualTypeOf<[number, FooBarSpread, ...FooBarSpread[]]>(); declare const tupleIntoTupleWithVariadicReplace: MergeDeep<[number, ...Foo[]], [Bar, Bar, ...Bar[]], {arrayMergeMode: 'replace'; recurseIntoArrays: true}>; -expectType<[Bar, FooBarReplace, ...FooBarReplace[]]>(tupleIntoTupleWithVariadicReplace); +expectTypeOf(tupleIntoTupleWithVariadicReplace).toEqualTypeOf<[Bar, FooBarReplace, ...FooBarReplace[]]>(); declare const tupleIntoTupleWithVariadicReplaceReversed: MergeDeep<[Foo, ...Foo[]], [number, Bar, ...Bar[]], {arrayMergeMode: 'replace'; recurseIntoArrays: true}>; -expectType<[number, FooBarReplace, ...FooBarReplace[]]>(tupleIntoTupleWithVariadicReplaceReversed); +expectTypeOf(tupleIntoTupleWithVariadicReplaceReversed).toEqualTypeOf<[number, FooBarReplace, ...FooBarReplace[]]>(); diff --git a/test-d/merge-exclusive.ts b/test-d/merge-exclusive.ts index ea9f8eabf..8f272ce37 100644 --- a/test-d/merge-exclusive.ts +++ b/test-d/merge-exclusive.ts @@ -1,4 +1,4 @@ -import {expectNotAssignable, expectAssignable} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {MergeExclusive} from '../index'; type BaseOptions = { @@ -18,11 +18,7 @@ type Options = MergeExclusive; const exclusiveVariation1: Options = {exclusive1: true}; const exclusiveVariation2: Options = {exclusive2: 1}; -expectAssignable<{option?: string; exclusive1: boolean; exclusive2?: string}>( - exclusiveVariation1, -); -expectAssignable<{option?: string; exclusive1?: string; exclusive2: number}>( - exclusiveVariation2, -); +expectTypeOf(exclusiveVariation1).toMatchTypeOf<{option?: string; exclusive1: boolean; exclusive2?: string}>(); +expectTypeOf(exclusiveVariation2).toMatchTypeOf<{option?: string; exclusive1?: string; exclusive2: number}>(); -expectNotAssignable({exclusive1: true, exclusive2: 1}); +expectTypeOf<{exclusive1: true; exclusive2: 1}>().not.toMatchTypeOf(); diff --git a/test-d/merge.ts b/test-d/merge.ts index 2f5d1471d..c0e42e02a 100644 --- a/test-d/merge.ts +++ b/test-d/merge.ts @@ -1,4 +1,4 @@ -import {expectError, expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {Merge} from '../index'; type Foo = { @@ -11,7 +11,7 @@ type Bar = { }; const ab: Merge = {a: 1, b: 2}; -expectType<{a: number; b: number}>(ab); +expectTypeOf(ab).toEqualTypeOf<{a: number; b: number}>(); // eslint-disable-next-line @typescript-eslint/consistent-type-definitions interface FooInterface { @@ -39,23 +39,24 @@ const fooBar: FooBar = { baz: true, }; -expectType<{ +expectTypeOf(fooBar).toEqualTypeOf<{ [x: string]: unknown; [x: number]: number; [x: symbol]: boolean; foo: string; bar: Date; baz: boolean; -}>(fooBar); +}>(); declare function setFooBar(fooBar: FooBar): void; -expectError(setFooBar({ +// @ts-expect-error +setFooBar({ [Symbol(42)]: 'life', foo: 'foo', bar: new Date(), baz: true, -})); +}); // Checks that a property can be replaced by another property that is not of the same type. This issue was encountered in `MergeDeep' with the default options. type FooDefaultOptions = { @@ -64,7 +65,7 @@ type FooDefaultOptions = { type FooOptions = Merge; -expectType({stripUndefinedValues: true}); +expectTypeOf<{stripUndefinedValues: true}>().toEqualTypeOf(); // Test that optional keys are enforced. type FooWithOptionaKeys = { @@ -92,7 +93,7 @@ type FooBarWithOptionalKeys = Merge; declare const fooBarWithOptionalKeys: FooBarWithOptionalKeys; // Note that `c` and `g` is not marked as optional and this is deliberate, as this is the behaviour expected by the older version of Merge. This may change in a later version. -expectType<{ +expectTypeOf(fooBarWithOptionalKeys).toEqualTypeOf<{ [x: number]: number; [x: symbol]: boolean; [x: string]: unknown; @@ -103,7 +104,7 @@ expectType<{ e?: number; f?: number; g: undefined; -}>(fooBarWithOptionalKeys); +}>(); // Checks that an indexed key type can be overwritten. type FooWithIndexSignature = { @@ -126,11 +127,11 @@ type FooBarWithIndexSignature = Merge(fooBarWithIndexSignature); +}>(); diff --git a/test-d/multidimensional-array.ts b/test-d/multidimensional-array.ts index 9bf96d078..aed4efccf 100644 --- a/test-d/multidimensional-array.ts +++ b/test-d/multidimensional-array.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {MultidimensionalArray} from '../index'; function createArray(dimensions: T): MultidimensionalArray { @@ -24,7 +24,7 @@ a[0][0][0] = 42; type RecursiveArray = Array>; -expectType(a); -expectType>(b); -expectType(c); -expectType(d); +expectTypeOf(a).toEqualTypeOf(); +expectTypeOf(b).toEqualTypeOf>(); +expectTypeOf(c).toEqualTypeOf(); +expectTypeOf(d).toEqualTypeOf(); diff --git a/test-d/multidimensional-readonly-array.ts b/test-d/multidimensional-readonly-array.ts index 87807dfa0..a080b27a2 100644 --- a/test-d/multidimensional-readonly-array.ts +++ b/test-d/multidimensional-readonly-array.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {MultidimensionalReadonlyArray} from '../index'; function createArray(dimensions: T): MultidimensionalReadonlyArray { @@ -27,8 +27,8 @@ const answer = c[0][0]; // '42' type RecursiveArray = ReadonlyArray>; -expectType(answer); +expectTypeOf(answer).toEqualTypeOf(); -expectType>>(a); -expectType>(b); -expectType>(c); +expectTypeOf(a).toEqualTypeOf>>(); +expectTypeOf(b).toEqualTypeOf>(); +expectTypeOf(c).toEqualTypeOf>(); diff --git a/test-d/numeric.ts b/test-d/numeric.ts index 75466f5a8..01f097007 100644 --- a/test-d/numeric.ts +++ b/test-d/numeric.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type { Finite, Float, @@ -16,8 +16,8 @@ import type { declare const infinity: Finite; declare const infinityMixed: Finite<1 | PositiveInfinity | NegativeInfinity>; -expectType(infinity); -expectType<1>(infinityMixed); +expectTypeOf(infinity).toEqualTypeOf(); +expectTypeOf(infinityMixed).toEqualTypeOf<1>(); // Integer declare const integer: Integer<1>; @@ -25,10 +25,10 @@ declare const integerMixed: Integer<1 | 1.5>; declare const nonInteger: Integer<1.5>; declare const infinityInteger: Integer; -expectType<1>(integer); -expectType(integerMixed); // This may be undesired behavior -expectType(nonInteger); -expectType(infinityInteger); +expectTypeOf(integer).toEqualTypeOf<1>(); +expectTypeOf(integerMixed).toEqualTypeOf(); // This may be undesired behavior +expectTypeOf(nonInteger).toEqualTypeOf(); +expectTypeOf(infinityInteger).toEqualTypeOf(); // Float declare const float: Float<1.5>; @@ -36,32 +36,32 @@ declare const floatMixed: Float<1 | 1.5>; declare const nonFloat: Float<1>; declare const infinityFloat: Float; -expectType<1.5>(float); -expectType<1.5>(floatMixed); -expectType(nonFloat); -expectType(infinityFloat); // According to Number.isInteger +expectTypeOf(float).toEqualTypeOf<1.5>(); +expectTypeOf(floatMixed).toEqualTypeOf<1.5>(); +expectTypeOf(nonFloat).toEqualTypeOf(); +expectTypeOf(infinityFloat).toEqualTypeOf(); // According to Number.isInteger // Negative declare const negative: Negative<-1 | -1n | 0 | 0n | 1 | 1n>; -expectType<-1 | -1n>(negative); +expectTypeOf(negative).toEqualTypeOf<-1 | -1n>(); // NegativeInteger declare const negativeInteger: NegativeInteger<-1 | 0 | 1>; -expectType<-1>(negativeInteger); +expectTypeOf(negativeInteger).toEqualTypeOf<-1>(); // NegativeFloat declare const negativeFloat: NegativeFloat<-1.5 | -1 | 0 | 1 | 1.5>; -expectType<-1.5>(negativeFloat); +expectTypeOf(negativeFloat).toEqualTypeOf<-1.5>(); // NonNegative declare const nonNegative: NonNegative<-1 | -1n | 0 | 0n | 1 | 1n>; -expectType<0 | 0n | 1 | 1n>(nonNegative); +expectTypeOf(nonNegative).toEqualTypeOf<0 | 0n | 1 | 1n>(); // NonNegativeInteger declare const nonNegativeInteger: NonNegativeInteger<-1 | 0 | 1>; -expectType<0 | 1>(nonNegativeInteger); +expectTypeOf(nonNegativeInteger).toEqualTypeOf<0 | 1>(); diff --git a/test-d/omit-index-signature.ts b/test-d/omit-index-signature.ts index 21d0f60eb..fad966ca8 100644 --- a/test-d/omit-index-signature.ts +++ b/test-d/omit-index-signature.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {OmitIndexSignature} from '../index'; type ExampleInterface = { @@ -25,15 +25,15 @@ type MappedType = { }; declare const exampleInterfaceKnownKeys: OmitIndexSignature; -expectType<{ +expectTypeOf(exampleInterfaceKnownKeys).toEqualTypeOf<{ foo: 'bar'; qux?: 'baz'; -}>(exampleInterfaceKnownKeys); +}>(); declare const exampleMappedTypeKnownKeys: OmitIndexSignature< MappedType >; -expectType<{ +expectTypeOf(exampleMappedTypeKnownKeys).toEqualTypeOf<{ foo: {key: 'foo'; value: 'bar'}; qux?: {key: 'qux'; value: 'baz'}; -}>(exampleMappedTypeKnownKeys); +}>(); diff --git a/test-d/opaque.ts b/test-d/opaque.ts index c5c5843c4..4ab60c1f2 100644 --- a/test-d/opaque.ts +++ b/test-d/opaque.ts @@ -1,4 +1,4 @@ -import {expectAssignable, expectNotAssignable, expectNotType, expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {Opaque, UnwrapOpaque} from '../index'; type Value = Opaque; @@ -7,13 +7,13 @@ type Value = Opaque; const value: Value = 2 as Value; // The underlying type of the value is still a number. -expectAssignable(value); +expectTypeOf(value).toMatchTypeOf(); // You cannot modify an opaque value. -expectNotAssignable(value + 2); +expectTypeOf(value + 2).not.toMatchTypeOf(); type WithoutToken = Opaque; -expectAssignable(2 as WithoutToken); +expectTypeOf(2 as WithoutToken).toMatchTypeOf(); // Verify that the Opaque's token can be the parent type itself. type Person = { @@ -24,7 +24,7 @@ const person = { id: 42 as Opaque, name: 'Arthur', }; -expectType(person); +expectTypeOf(person).toEqualTypeOf(); // Failing test for https://github.com/sindresorhus/type-fest/issues/108 // Use `Opaque` value as `Record` index type. @@ -40,12 +40,12 @@ const userEntities: NormalizedDictionary = { const johnsId = '7dd4a16e-d5ee-454c-b1d0-71e23d9fa70b' as UUID; const userJohn = userEntities[johnsId]; -expectType(userJohn); +expectTypeOf(userJohn).toEqualTypeOf(); // Remove tag from opaque value. // Note: This will simply return number as type. type PlainValue = UnwrapOpaque; -expectAssignable(123); +expectTypeOf<123>().toMatchTypeOf(); const plainValue: PlainValue = 123 as PlainValue; -expectNotType(plainValue); +expectTypeOf(plainValue).not.toEqualTypeOf(); diff --git a/test-d/optional-keys-of.ts b/test-d/optional-keys-of.ts index 182f3fb0e..7a5443963 100644 --- a/test-d/optional-keys-of.ts +++ b/test-d/optional-keys-of.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {OptionalKeysOf} from '../index'; type TestType1 = { @@ -24,6 +24,6 @@ declare const test1: OptionalKeysOf1; declare const test2: OptionalKeysOf2; declare const test3: OptionalKeysOf3; -expectType<'b'>(test1); -expectType<'a' | 'b'>(test2); -expectType(test3); +expectTypeOf(test1).toEqualTypeOf<'b'>(); +expectTypeOf(test2).toEqualTypeOf<'a' | 'b'>(); +expectTypeOf(test3).toEqualTypeOf(); diff --git a/test-d/package-json.ts b/test-d/package-json.ts index 23812e779..f061c7dab 100644 --- a/test-d/package-json.ts +++ b/test-d/package-json.ts @@ -1,63 +1,63 @@ -import {expectType, expectAssignable, expectNotAssignable, expectError} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {PackageJson, LiteralUnion, JsonObject} from '../index'; const packageJson: PackageJson = {}; -expectType(packageJson.name); -expectType(packageJson.version); -expectType(packageJson.description); -expectType(packageJson.keywords); -expectType | undefined>(packageJson.homepage); -expectType(packageJson.bugs); -expectType(packageJson.license); -expectType | undefined>(packageJson.licenses); -expectType(packageJson.author); -expectType(packageJson.contributors); -expectType(packageJson.maintainers); -expectType(packageJson.files); -expectType(packageJson.main); -expectType(packageJson.packageManager); -expectType> | undefined>(packageJson.bin); -expectType(packageJson.types); -expectType(packageJson.typings); -expectType(packageJson.man); -expectType(packageJson.directories); -expectType<{type: string; url: string; directory?: string} | string | undefined>( +expectTypeOf(packageJson.name).toEqualTypeOf(); +expectTypeOf(packageJson.version).toEqualTypeOf(); +expectTypeOf(packageJson.description).toEqualTypeOf(); +expectTypeOf(packageJson.keywords).toEqualTypeOf(); +expectTypeOf(packageJson.homepage).toEqualTypeOf | undefined>(); +expectTypeOf(packageJson.bugs).toEqualTypeOf(); +expectTypeOf(packageJson.license).toEqualTypeOf(); +expectTypeOf(packageJson.licenses).toEqualTypeOf | undefined>(); +expectTypeOf(packageJson.author).toEqualTypeOf(); +expectTypeOf(packageJson.contributors).toEqualTypeOf(); +expectTypeOf(packageJson.maintainers).toEqualTypeOf(); +expectTypeOf(packageJson.files).toEqualTypeOf(); +expectTypeOf(packageJson.main).toEqualTypeOf(); +expectTypeOf(packageJson.packageManager).toEqualTypeOf(); +expectTypeOf(packageJson.bin).toEqualTypeOf> | undefined>(); +expectTypeOf(packageJson.types).toEqualTypeOf(); +expectTypeOf(packageJson.typings).toEqualTypeOf(); +expectTypeOf(packageJson.man).toEqualTypeOf(); +expectTypeOf(packageJson.directories).toEqualTypeOf(); +expectTypeOf( packageJson.repository, -); -expectType(packageJson.scripts); -expectType(packageJson.config); -expectType(packageJson.dependencies); -expectType(packageJson.devDependencies); -expectType( +).toEqualTypeOf<{type: string; url: string; directory?: string} | string | undefined>(); +expectTypeOf(packageJson.scripts).toEqualTypeOf(); +expectTypeOf(packageJson.config).toEqualTypeOf(); +expectTypeOf(packageJson.dependencies).toEqualTypeOf(); +expectTypeOf(packageJson.devDependencies).toEqualTypeOf(); +expectTypeOf( packageJson.optionalDependencies, -); -expectType(packageJson.peerDependencies); -expectType(packageJson.bundleDependencies); -expectType(packageJson.bundledDependencies); -expectType(packageJson.resolutions); -expectType(packageJson.workspaces); -expectType> | undefined>(packageJson.engines); -expectType(packageJson.engineStrict); -expectAssignable< +).toEqualTypeOf(); +expectTypeOf(packageJson.peerDependencies).toEqualTypeOf(); +expectTypeOf(packageJson.bundleDependencies).toEqualTypeOf(); +expectTypeOf(packageJson.bundledDependencies).toEqualTypeOf(); +expectTypeOf(packageJson.resolutions).toEqualTypeOf(); +expectTypeOf(packageJson.workspaces).toEqualTypeOf(); +expectTypeOf(packageJson.engines).toEqualTypeOf> | undefined>(); +expectTypeOf(packageJson.engineStrict).toEqualTypeOf(); +expectTypeOf(packageJson.os).toMatchTypeOf< | undefined | Array> ->(packageJson.os); -expectAssignable< +>(); +expectTypeOf(packageJson.cpu).toMatchTypeOf< | undefined | Array> ->(packageJson.cpu); -expectType(packageJson.preferGlobal); -expectType(packageJson.private); -expectType(packageJson.publishConfig); -expectType(packageJson.module); -expectType< +>(); +expectTypeOf(packageJson.preferGlobal).toEqualTypeOf(); +expectTypeOf(packageJson.private).toEqualTypeOf(); +expectTypeOf(packageJson.publishConfig).toEqualTypeOf(); +expectTypeOf(packageJson.module).toEqualTypeOf(); +expectTypeOf(packageJson.esnext).toEqualTypeOf< | string | { [moduleName: string]: string | undefined; @@ -65,36 +65,38 @@ expectType< browser?: string; } | undefined ->(packageJson.esnext); -expectType(packageJson.jspm); +>(); +expectTypeOf(packageJson.jspm).toEqualTypeOf(); // Undefined assigns -expectAssignable({dep: undefined}); -expectAssignable({engine: undefined}); -expectAssignable({unknownScript: undefined}); -expectAssignable({bin: undefined}); -expectAssignable({ +expectTypeOf<{dep: undefined}>().toMatchTypeOf(); +expectTypeOf<{engine: undefined}>().toMatchTypeOf(); +expectTypeOf<{unknownScript: undefined}>().toMatchTypeOf(); +expectTypeOf<{bin: undefined}>().toMatchTypeOf(); +expectTypeOf({ '>=4': { '*': ['src'], somethingElse: undefined, }, '<4': undefined, -}); +}).toMatchTypeOf(); // Must reject an object that contains properties with `undefined` values. // See https://github.com/sindresorhus/type-fest/issues/272 declare function setConfig(config: JsonObject): void; -expectError(setConfig({bugs: undefined})); -expectError(setConfig({bugs: {life: undefined}})); +// @ts-expect-error +setConfig({bugs: undefined}); +// @ts-expect-error +setConfig({bugs: {life: undefined}}); -expectNotAssignable({bugs: undefined}); -expectNotAssignable({bugs: {life: undefined}}); +expectTypeOf<{bugs: undefined}>().not.toMatchTypeOf(); +expectTypeOf<{bugs: {life: undefined}}>().not.toMatchTypeOf(); -expectAssignable({}); -expectAssignable({bugs: 42}); -expectAssignable({bugs: [42]}); -expectAssignable({bugs: {life: 42}}); +expectTypeOf<{}>().toMatchTypeOf(); +expectTypeOf<{bugs: 42}>().toMatchTypeOf(); +expectTypeOf<{bugs: [42]}>().toMatchTypeOf(); +expectTypeOf<{bugs: {life: 42}}>().toMatchTypeOf(); // `PackageJson` should be a valid `JsonObject`. // See https://github.com/sindresorhus/type-fest/issues/79 @@ -103,8 +105,8 @@ type UnknownRecord = Record; const unknownRecord: UnknownRecord = {}; const jsonObject: JsonObject = {}; -expectAssignable(packageJson); -expectNotAssignable(unknownRecord); +expectTypeOf(packageJson).toMatchTypeOf(); +expectTypeOf(unknownRecord).not.toMatchTypeOf(); -expectAssignable(jsonObject); -expectAssignable(packageJson); +expectTypeOf(jsonObject).toMatchTypeOf(); +expectTypeOf(packageJson).toMatchTypeOf(); diff --git a/test-d/partial-deep.ts b/test-d/partial-deep.ts index 5ef3a478c..24cf97ffd 100644 --- a/test-d/partial-deep.ts +++ b/test-d/partial-deep.ts @@ -1,4 +1,4 @@ -import {expectType, expectError, expectAssignable} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {PartialDeep} from '../index'; const foo = { @@ -27,27 +27,27 @@ const foo = { let partialDeepFoo: PartialDeep = foo; -expectError(expectType>(partialDeepFoo)); +expectTypeOf(partialDeepFoo).not.toEqualTypeOf>(); const partialDeepBar: PartialDeep = foo.bar; -expectType(partialDeepFoo.bar); -expectType<((_: string) => void) | undefined>(partialDeepFoo.bar!.function); -expectAssignable(partialDeepFoo.bar!.object); -expectType(partialDeepFoo.bar!.string); -expectType(partialDeepFoo.bar!.number); -expectType(partialDeepFoo.bar!.boolean); -expectType(partialDeepFoo.bar!.date); -expectType(partialDeepFoo.bar!.regexp); -expectType(partialDeepFoo.bar!.symbol); -expectType(partialDeepFoo.bar!.null); -expectType(partialDeepFoo.bar!.undefined); -expectAssignable | undefined>(partialDeepFoo.bar!.map); -expectAssignable | undefined>(partialDeepFoo.bar!.set); -expectType | undefined>(partialDeepFoo.bar!.array); -expectType<['foo'?] | undefined>(partialDeepFoo.bar!.tuple); -expectAssignable | undefined>(partialDeepFoo.bar!.readonlyMap); -expectAssignable | undefined>(partialDeepFoo.bar!.readonlySet); -expectType | undefined>(partialDeepFoo.bar!.readonlyArray); -expectType(partialDeepFoo.bar!.readonlyTuple); +expectTypeOf(partialDeepFoo.bar).toEqualTypeOf(); +expectTypeOf(partialDeepFoo.bar!.function).toEqualTypeOf<((_: string) => void) | undefined>(); +expectTypeOf(partialDeepFoo.bar!.object).toMatchTypeOf(); +expectTypeOf(partialDeepFoo.bar!.string).toEqualTypeOf(); +expectTypeOf(partialDeepFoo.bar!.number).toEqualTypeOf(); +expectTypeOf(partialDeepFoo.bar!.boolean).toEqualTypeOf(); +expectTypeOf(partialDeepFoo.bar!.date).toEqualTypeOf(); +expectTypeOf(partialDeepFoo.bar!.regexp).toEqualTypeOf(); +expectTypeOf(partialDeepFoo.bar!.symbol).toEqualTypeOf(); +expectTypeOf(partialDeepFoo.bar!.null).toEqualTypeOf(); +expectTypeOf(partialDeepFoo.bar!.undefined).toEqualTypeOf(); +expectTypeOf(partialDeepFoo.bar!.map).toMatchTypeOf | undefined>(); +expectTypeOf(partialDeepFoo.bar!.set).toMatchTypeOf | undefined>(); +expectTypeOf(partialDeepFoo.bar!.array).toEqualTypeOf | undefined>(); +expectTypeOf(partialDeepFoo.bar!.tuple).toEqualTypeOf<['foo'?] | undefined>(); +expectTypeOf(partialDeepFoo.bar!.readonlyMap).toMatchTypeOf | undefined>(); +expectTypeOf(partialDeepFoo.bar!.readonlySet).toMatchTypeOf | undefined>(); +expectTypeOf(partialDeepFoo.bar!.readonlyArray).toEqualTypeOf | undefined>(); +expectTypeOf(partialDeepFoo.bar!.readonlyTuple).toEqualTypeOf(); // Check for compiling with omitting partial keys partialDeepFoo = {baz: 'fred'}; partialDeepFoo = {bar: {string: 'waldo'}}; @@ -62,31 +62,31 @@ type Recurse = | Recurse[]; type RecurseObject = {value: Recurse}; const recurseObject: RecurseObject = {value: null}; -expectAssignable>(recurseObject); +expectTypeOf(recurseObject).toMatchTypeOf>(); // Check that `{recurseIntoArrays: false}` is the default const partialDeepNoRecurseIntoArraysFoo: PartialDeep = foo; // Check that `{recurseIntoArrays: true}` behaves as intended -expectType>(partialDeepFoo); +expectTypeOf(partialDeepFoo).toEqualTypeOf>(); // These are mostly the same checks as before, but the array/tuple types are different. -expectError(expectType>(partialDeepNoRecurseIntoArraysFoo)); +expectTypeOf(partialDeepNoRecurseIntoArraysFoo).not.toEqualTypeOf>(); const partialDeepNoRecurseIntoArraysBar: PartialDeep = foo.bar; -expectType(partialDeepNoRecurseIntoArraysFoo.bar); -expectType<((_: string) => void) | undefined>(partialDeepNoRecurseIntoArraysBar.function); -expectAssignable(partialDeepNoRecurseIntoArraysBar.object); -expectType(partialDeepNoRecurseIntoArraysBar.string); -expectType(partialDeepNoRecurseIntoArraysBar.number); -expectType(partialDeepNoRecurseIntoArraysBar.boolean); -expectType(partialDeepNoRecurseIntoArraysBar.date); -expectType(partialDeepNoRecurseIntoArraysBar.regexp); -expectType(partialDeepNoRecurseIntoArraysBar.symbol); -expectType(partialDeepNoRecurseIntoArraysBar.null); -expectType(partialDeepNoRecurseIntoArraysBar.undefined); -expectAssignable | undefined>(partialDeepNoRecurseIntoArraysBar.map); -expectAssignable | undefined>(partialDeepNoRecurseIntoArraysBar.set); -expectType(partialDeepNoRecurseIntoArraysBar.array); -expectType<['foo'] | undefined>(partialDeepNoRecurseIntoArraysBar.tuple); -expectAssignable | undefined>(partialDeepNoRecurseIntoArraysBar.readonlyMap); -expectAssignable | undefined>(partialDeepNoRecurseIntoArraysBar.readonlySet); -expectType(partialDeepNoRecurseIntoArraysBar.readonlyArray); -expectType(partialDeepNoRecurseIntoArraysBar.readonlyTuple); +expectTypeOf(partialDeepNoRecurseIntoArraysFoo.bar).toEqualTypeOf(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.function).toEqualTypeOf<((_: string) => void) | undefined>(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.object).toMatchTypeOf(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.string).toEqualTypeOf(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.number).toEqualTypeOf(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.boolean).toEqualTypeOf(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.date).toEqualTypeOf(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.regexp).toEqualTypeOf(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.symbol).toEqualTypeOf(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.null).toEqualTypeOf(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.undefined).toEqualTypeOf(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.map).toMatchTypeOf | undefined>(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.set).toMatchTypeOf | undefined>(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.array).toEqualTypeOf(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.tuple).toEqualTypeOf<['foo'] | undefined>(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.readonlyMap).toMatchTypeOf | undefined>(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.readonlySet).toMatchTypeOf | undefined>(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.readonlyArray).toEqualTypeOf(); +expectTypeOf(partialDeepNoRecurseIntoArraysBar.readonlyTuple).toEqualTypeOf(); diff --git a/test-d/partial-on-undefined-deep.ts b/test-d/partial-on-undefined-deep.ts index e1e8444df..b6f0ba376 100644 --- a/test-d/partial-on-undefined-deep.ts +++ b/test-d/partial-on-undefined-deep.ts @@ -1,4 +1,4 @@ -import {expectAssignable} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {PartialOnUndefinedDeep} from '../index'; type TestingType = { @@ -27,7 +27,7 @@ type TestingType = { // Default behavior, without recursion into arrays/tuples declare const foo: PartialOnUndefinedDeep; -expectAssignable<{ +expectTypeOf(foo).toMatchTypeOf<{ function?: TestingType['function']; object?: TestingType['object']; objectDeep: { @@ -49,11 +49,11 @@ expectAssignable<{ readonly1?: TestingType['readonly1']; readonly2?: TestingType['readonly2']; tuple?: TestingType['tuple']; -}>(foo); +}>(); // With recursion into arrays/tuples activated declare const bar: PartialOnUndefinedDeep; -expectAssignable<{ +expectTypeOf(bar).toMatchTypeOf<{ function?: TestingType['function']; object?: TestingType['object']; objectDeep: { @@ -75,4 +75,4 @@ expectAssignable<{ readonly1?: TestingType['readonly1']; readonly2?: ReadonlyArray<{propertyA: string; propertyB?: number | undefined}> | undefined; tuple?: ['test1', {propertyA: string; propertyB?: number | undefined}] | undefined; -}>(bar); +}>(); diff --git a/test-d/pascal-case.ts b/test-d/pascal-case.ts index cfa99f7c7..9a280be8a 100644 --- a/test-d/pascal-case.ts +++ b/test-d/pascal-case.ts @@ -1,11 +1,11 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {PascalCase} from '../index'; const pascalFromCamel: PascalCase<'fooBar'> = 'FooBar'; -expectType<'FooBar'>(pascalFromCamel); +expectTypeOf(pascalFromCamel).toEqualTypeOf<'FooBar'>(); const pascalFromKebab: PascalCase<'foo-bar'> = 'FooBar'; -expectType<'FooBar'>(pascalFromKebab); +expectTypeOf(pascalFromKebab).toEqualTypeOf<'FooBar'>(); const pascalFromComplexKebab: PascalCase<'foo-bar-abc-123'> = 'FooBarAbc123'; -expectType<'FooBarAbc123'>(pascalFromComplexKebab); +expectTypeOf(pascalFromComplexKebab).toEqualTypeOf<'FooBarAbc123'>(); diff --git a/test-d/pascal-cased-properties-deep.ts b/test-d/pascal-cased-properties-deep.ts index 91b3512ec..d034a066c 100644 --- a/test-d/pascal-cased-properties-deep.ts +++ b/test-d/pascal-cased-properties-deep.ts @@ -1,14 +1,14 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {PascalCasedPropertiesDeep} from '../index'; declare const foo: PascalCasedPropertiesDeep<{helloWorld: {fooBar: string}}>; -expectType<{HelloWorld: {FooBar: string}}>(foo); +expectTypeOf(foo).toEqualTypeOf<{HelloWorld: {FooBar: string}}>(); declare const fooBar: PascalCasedPropertiesDeep<() => {a: string}>; -expectType<() => {a: string}>(fooBar); +expectTypeOf(fooBar).toEqualTypeOf<() => {a: string}>(); declare const bar: PascalCasedPropertiesDeep>; -expectType>(bar); +expectTypeOf(bar).toEqualTypeOf>(); // Verify example type User = { @@ -45,4 +45,4 @@ const result: PascalCasedPropertiesDeep = { }, ], }; -expectType>(result); +expectTypeOf(result).toEqualTypeOf>(); diff --git a/test-d/pascal-cased-properties.ts b/test-d/pascal-cased-properties.ts index bae235597..a8b848eb2 100644 --- a/test-d/pascal-cased-properties.ts +++ b/test-d/pascal-cased-properties.ts @@ -1,14 +1,14 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {PascalCasedProperties} from '../index'; declare const foo: PascalCasedProperties<{helloWorld: {fooBar: string}}>; -expectType<{HelloWorld: {fooBar: string}}>(foo); +expectTypeOf(foo).toEqualTypeOf<{HelloWorld: {fooBar: string}}>(); declare const bar: PascalCasedProperties>; -expectType>(bar); +expectTypeOf(bar).toEqualTypeOf>(); declare const fooBar: PascalCasedProperties<() => {a: string}>; -expectType<() => {a: string}>(fooBar); +expectTypeOf(fooBar).toEqualTypeOf<() => {a: string}>(); // Verify example type User = { @@ -19,4 +19,4 @@ const result: PascalCasedProperties = { UserId: 1, UserName: 'Tom', }; -expectType>(result); +expectTypeOf(result).toEqualTypeOf>(); diff --git a/test-d/pick-index-signature.ts b/test-d/pick-index-signature.ts index 27b1281b6..f4943255f 100644 --- a/test-d/pick-index-signature.ts +++ b/test-d/pick-index-signature.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {PickIndexSignature, Simplify} from '../index'; declare const symbolKey: unique symbol; @@ -25,4 +25,4 @@ type FooBar = Simplify; declare const indexSignature: PickIndexSignature; -expectType(indexSignature); +expectTypeOf(indexSignature).toEqualTypeOf(); diff --git a/test-d/promisable.ts b/test-d/promisable.ts index b6012d4e5..4ae80ecc7 100644 --- a/test-d/promisable.ts +++ b/test-d/promisable.ts @@ -1,5 +1,5 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {Promisable} from '../index'; declare const promisable: Promisable; -expectType | string>(promisable); +expectTypeOf(promisable).toEqualTypeOf | string>(); diff --git a/test-d/readonly-deep.ts b/test-d/readonly-deep.ts index 77ce27656..70e4c8f48 100644 --- a/test-d/readonly-deep.ts +++ b/test-d/readonly-deep.ts @@ -1,4 +1,4 @@ -import {expectType, expectError} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {ReadonlyDeep} from '../index'; import type {ReadonlyObjectDeep} from '../source/readonly-deep'; @@ -49,32 +49,33 @@ readonlyData.fn('foo'); readonlyData.fnWithOverload(1); readonlyData.fnWithOverload('', 1); -expectError(readonlyData.string = 'bar'); -expectType<{readonly foo: string}>(readonlyData.object); -expectType(readonlyData.string); -expectType(readonlyData.number); -expectType(readonlyData.boolean); -expectType(readonlyData.symbol); -expectType(readonlyData.null); -expectType(readonlyData.undefined); -expectType(readonlyData.date); -expectType(readonlyData.regExp); -expectType>>(readonlyData.map); -expectType>>(readonlyData.set); -expectType(readonlyData.array); -expectType(readonlyData.tuple); -expectType>>(readonlyData.readonlyMap); -expectType>>(readonlyData.readonlySet); -expectType(readonlyData.readonlyArray); -expectType(readonlyData.readonlyTuple); +// @ts-expect-error +readonlyData.string = 'bar'; +expectTypeOf(readonlyData.object).toEqualTypeOf<{readonly foo: string}>(); +expectTypeOf(readonlyData.string).toEqualTypeOf(); +expectTypeOf(readonlyData.number).toEqualTypeOf(); +expectTypeOf(readonlyData.boolean).toEqualTypeOf(); +expectTypeOf(readonlyData.symbol).toEqualTypeOf(); +expectTypeOf(readonlyData.null).toEqualTypeOf(); +expectTypeOf(readonlyData.undefined).toEqualTypeOf(); +expectTypeOf(readonlyData.date).toEqualTypeOf(); +expectTypeOf(readonlyData.regExp).toEqualTypeOf(); +expectTypeOf(readonlyData.map).toEqualTypeOf>>(); +expectTypeOf(readonlyData.set).toEqualTypeOf>>(); +expectTypeOf(readonlyData.array).toEqualTypeOf(); +expectTypeOf(readonlyData.tuple).toEqualTypeOf(); +expectTypeOf(readonlyData.readonlyMap).toEqualTypeOf>>(); +expectTypeOf(readonlyData.readonlySet).toEqualTypeOf>>(); +expectTypeOf(readonlyData.readonlyArray).toEqualTypeOf(); +expectTypeOf(readonlyData.readonlyTuple).toEqualTypeOf(); -expectType<((foo: number) => string) & ReadonlyObjectDeep>(readonlyData.namespace); -expectType(readonlyData.namespace(1)); -expectType(readonlyData.namespace.baz); +expectTypeOf(readonlyData.namespace).toEqualTypeOf<((foo: number) => string) & ReadonlyObjectDeep>(); +expectTypeOf(readonlyData.namespace(1)).toEqualTypeOf(); +expectTypeOf(readonlyData.namespace.baz).toEqualTypeOf(); // These currently aren't readonly due to TypeScript limitations. // @see https://github.com/microsoft/TypeScript/issues/29732 -expectType(readonlyData.namespaceWithOverload); -expectType(readonlyData.namespaceWithOverload(1)); -expectType(readonlyData.namespaceWithOverload('foo', 1)); -expectType(readonlyData.namespaceWithOverload.baz); +expectTypeOf(readonlyData.namespaceWithOverload).toEqualTypeOf(); +expectTypeOf(readonlyData.namespaceWithOverload(1)).toEqualTypeOf(); +expectTypeOf(readonlyData.namespaceWithOverload('foo', 1)).toEqualTypeOf(); +expectTypeOf(readonlyData.namespaceWithOverload.baz).toEqualTypeOf(); diff --git a/test-d/readonly-tuple.ts b/test-d/readonly-tuple.ts index 06527b141..23dc39ef9 100644 --- a/test-d/readonly-tuple.ts +++ b/test-d/readonly-tuple.ts @@ -1,16 +1,19 @@ -import {expectAssignable, expectError, expectNotAssignable} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {ReadonlyTuple} from '../index'; type TupleOfThreeStrings = ReadonlyTuple; -expectAssignable(['a', 'b', 'c']); +expectTypeOf<['a', 'b', 'c']>().toMatchTypeOf(); -expectNotAssignable(['a', 'b', 123]); -expectNotAssignable(['a']); -expectNotAssignable(['a', 'b']); -expectNotAssignable(['a', 'b', 'c', 'd']); +expectTypeOf<['a', 'b', 123]>().not.toMatchTypeOf(); +expectTypeOf<['a']>().not.toMatchTypeOf(); +expectTypeOf<['a', 'b']>().not.toMatchTypeOf(); +expectTypeOf<['a', 'b', 'c', 'd']>().not.toMatchTypeOf(); declare const test: TupleOfThreeStrings; -expectError(test.push); -expectError(test[2] = 'a'); +// @ts-expect-error +// eslint-disable-next-line @typescript-eslint/no-unused-expressions +test.push; +// @ts-expect-error +test[2] = 'a'; diff --git a/test-d/replace.ts b/test-d/replace.ts index 92ec34291..21bdf53c4 100644 --- a/test-d/replace.ts +++ b/test-d/replace.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {Replace} from '../index'; declare function replace< @@ -21,9 +21,9 @@ declare function replaceAll< replacement: Replacement ): Replace; -expectType<'hello 🦄'>(replace('hello ?', '?', '🦄')); -expectType<'hello ❓?'>(replace('hello ??', '?', '❓')); -expectType<'10-42-00'>(replaceAll('10:42:00', ':', '-')); -expectType<'userName'>(replaceAll('__userName__', '__', '')); -expectType<'MyCoolTitle'>(replaceAll('My Cool Title', ' ', '')); -expectType<'fobarfobar'>(replaceAll('foobarfoobar', 'ob', 'b')); +expectTypeOf(replace('hello ?', '?', '🦄')).toEqualTypeOf<'hello 🦄'>(); +expectTypeOf(replace('hello ??', '?', '❓')).toEqualTypeOf<'hello ❓?'>(); +expectTypeOf(replaceAll('10:42:00', ':', '-')).toEqualTypeOf<'10-42-00'>(); +expectTypeOf(replaceAll('__userName__', '__', '')).toEqualTypeOf<'userName'>(); +expectTypeOf(replaceAll('My Cool Title', ' ', '')).toEqualTypeOf<'MyCoolTitle'>(); +expectTypeOf(replaceAll('foobarfoobar', 'ob', 'b')).toEqualTypeOf<'fobarfobar'>(); diff --git a/test-d/require-all-or-none.ts b/test-d/require-all-or-none.ts index 1adcc9536..3263b4d8a 100644 --- a/test-d/require-all-or-none.ts +++ b/test-d/require-all-or-none.ts @@ -1,4 +1,4 @@ -import {expectError, expectAssignable} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {RequireAllOrNone} from '../index'; type SystemMessages = { @@ -16,9 +16,12 @@ const test = (_: ValidMessages): void => {}; // eslint-disable-line @typescript- test({default: 'hello'}); test({macos: 'yo', linux: 'sup', optional: 'howdy', default: 'hello'}); -expectError(test({})); -expectError(test({macos: 'hey', default: 'hello'})); -expectError(test({linux: 'hey', default: 'hello'})); +// @ts-expect-error +test({}); +// @ts-expect-error +test({macos: 'hey', default: 'hello'}); +// @ts-expect-error +test({linux: 'hey', default: 'hello'}); declare const oneWithoutKeys: RequireAllOrNone<{a: number; b: number}>; -expectAssignable<{a: number; b: number}>(oneWithoutKeys); +expectTypeOf(oneWithoutKeys).toMatchTypeOf<{a: number; b: number}>(); diff --git a/test-d/require-at-least-one.ts b/test-d/require-at-least-one.ts index 66ef26538..84d39e40d 100644 --- a/test-d/require-at-least-one.ts +++ b/test-d/require-at-least-one.ts @@ -1,4 +1,4 @@ -import {expectError, expectAssignable} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {RequireAtLeastOne} from '../index'; type SystemMessages = { @@ -23,19 +23,22 @@ test({macos: 'hey', default: 'hello'}); test({linux: 'sup', default: 'hello', optional: 'howdy'}); test({macos: 'hey', linux: 'sup', windows: 'hi', default: 'hello'}); -expectError(test({})); -expectError(test({macos: 'hey'})); -expectError(test({default: 'hello'})); +// @ts-expect-error +test({}); +// @ts-expect-error +test({macos: 'hey'}); +// @ts-expect-error +test({default: 'hello'}); declare const atLeastOneWithoutKeys: RequireAtLeastOne<{ a: number; b: number; }>; -expectAssignable<{a: number; b?: number} | {a?: number; b: number}>( +expectTypeOf( atLeastOneWithoutKeys, -); +).toMatchTypeOf<{a: number; b?: number} | {a?: number; b: number}>(); -expectAssignable>( +expectTypeOf( ({macos = '', linux = '🐧', windows = '⊞'}) => `${linux} + ${windows} = ${macos}`, -); +).toMatchTypeOf>(); diff --git a/test-d/require-exactly-one.ts b/test-d/require-exactly-one.ts index 5180b5554..f1a7f4e9d 100644 --- a/test-d/require-exactly-one.ts +++ b/test-d/require-exactly-one.ts @@ -1,4 +1,4 @@ -import {expectError, expectAssignable} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {RequireExactlyOne} from '../index'; type SystemMessages = { @@ -16,9 +16,11 @@ const test = (_: ValidMessages): void => {}; // eslint-disable-line @typescript- test({macos: 'hey', default: 'hello'}); test({linux: 'sup', optional: 'howdy', default: 'hello'}); -expectError(test({})); -expectError(test({macos: 'hey', linux: 'sup', default: 'hello'})); +// @ts-expect-error +test({}); +// @ts-expect-error +test({macos: 'hey', linux: 'sup', default: 'hello'}); declare const oneWithoutKeys: RequireExactlyOne<{a: number; b: number}>; -expectAssignable<{a: number} | {b: number}>(oneWithoutKeys); -expectError(expectAssignable<{a: number; b: number}>(oneWithoutKeys)); +expectTypeOf(oneWithoutKeys).toMatchTypeOf<{a: number} | {b: number}>(); +expectTypeOf(oneWithoutKeys).not.toMatchTypeOf<{a: number; b: number}>(); diff --git a/test-d/required-keys-of.ts b/test-d/required-keys-of.ts index 64fd0ed38..afb5ee020 100644 --- a/test-d/required-keys-of.ts +++ b/test-d/required-keys-of.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {RequiredKeysOf} from '../index'; type TestType1 = { @@ -24,6 +24,6 @@ declare const test1: RequiredKeysOf1; declare const test2: RequiredKeysOf2; declare const test3: RequiredKeysOf3; -expectType<'a'>(test1); -expectType(test2); -expectType<'a' | 'b'>(test3); +expectTypeOf(test1).toEqualTypeOf<'a'>(); +expectTypeOf(test2).toEqualTypeOf(); +expectTypeOf(test3).toEqualTypeOf<'a' | 'b'>(); diff --git a/test-d/schema.ts b/test-d/schema.ts index 3200ea78c..7b37a4a06 100644 --- a/test-d/schema.ts +++ b/test-d/schema.ts @@ -1,4 +1,4 @@ -import {expectNotAssignable, expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {Schema} from '../index'; const foo = { @@ -46,27 +46,27 @@ const fooSchema: FooSchema = { }, }; -expectNotAssignable(foo); -expectNotAssignable({key: 'value'}); -expectNotAssignable(new Date()); -expectType(fooSchema.baz); +expectTypeOf(foo).not.toMatchTypeOf(); +expectTypeOf<{key: 'value'}>().not.toMatchTypeOf(); +expectTypeOf(new Date()).not.toMatchTypeOf(); +expectTypeOf(fooSchema.baz).toEqualTypeOf(); const barSchema = fooSchema.bar as Schema; -expectType(barSchema.function); -expectType(barSchema.object); -expectType(barSchema.string); -expectType(barSchema.number); -expectType(barSchema.boolean); -expectType(barSchema.symbol); -expectType(barSchema.map); -expectType(barSchema.set); -expectType(barSchema.array); -expectType(barSchema.tuple); -expectType(barSchema.readonlyMap); -expectType(barSchema.readonlySet); -expectType(barSchema.readonlyArray); -expectType(barSchema.readonlyTuple); -expectType(barSchema.regExp); +expectTypeOf(barSchema.function).toEqualTypeOf(); +expectTypeOf(barSchema.object).toEqualTypeOf(); +expectTypeOf(barSchema.string).toEqualTypeOf(); +expectTypeOf(barSchema.number).toEqualTypeOf(); +expectTypeOf(barSchema.boolean).toEqualTypeOf(); +expectTypeOf(barSchema.symbol).toEqualTypeOf(); +expectTypeOf(barSchema.map).toEqualTypeOf(); +expectTypeOf(barSchema.set).toEqualTypeOf(); +expectTypeOf(barSchema.array).toEqualTypeOf(); +expectTypeOf(barSchema.tuple).toEqualTypeOf(); +expectTypeOf(barSchema.readonlyMap).toEqualTypeOf(); +expectTypeOf(barSchema.readonlySet).toEqualTypeOf(); +expectTypeOf(barSchema.readonlyArray).toEqualTypeOf(); +expectTypeOf(barSchema.readonlyTuple).toEqualTypeOf(); +expectTypeOf(barSchema.regExp).toEqualTypeOf(); type ComplexOption = { type: 'readonly' | 'required' | 'optional'; @@ -102,22 +102,22 @@ const complexFoo: ComplexSchema = { }, }; -expectNotAssignable(foo); -expectType(complexFoo.baz); +expectTypeOf(foo).not.toMatchTypeOf(); +expectTypeOf(complexFoo.baz).toEqualTypeOf(); const complexBarSchema = complexFoo.bar as Schema; -expectType(complexBarSchema.function); -expectType(complexBarSchema.object); -expectType(complexBarSchema.string); -expectType(complexBarSchema.number); -expectType(complexBarSchema.boolean); -expectType(complexBarSchema.symbol); -expectType(complexBarSchema.map); -expectType(complexBarSchema.set); -expectType(complexBarSchema.array); -expectType(complexBarSchema.tuple); -expectType(complexBarSchema.readonlyMap); -expectType(complexBarSchema.readonlySet); -expectType(complexBarSchema.readonlyArray); -expectType(complexBarSchema.readonlyTuple); -expectType(complexBarSchema.regExp); +expectTypeOf(complexBarSchema.function).toEqualTypeOf(); +expectTypeOf(complexBarSchema.object).toEqualTypeOf(); +expectTypeOf(complexBarSchema.string).toEqualTypeOf(); +expectTypeOf(complexBarSchema.number).toEqualTypeOf(); +expectTypeOf(complexBarSchema.boolean).toEqualTypeOf(); +expectTypeOf(complexBarSchema.symbol).toEqualTypeOf(); +expectTypeOf(complexBarSchema.map).toEqualTypeOf(); +expectTypeOf(complexBarSchema.set).toEqualTypeOf(); +expectTypeOf(complexBarSchema.array).toEqualTypeOf(); +expectTypeOf(complexBarSchema.tuple).toEqualTypeOf(); +expectTypeOf(complexBarSchema.readonlyMap).toEqualTypeOf(); +expectTypeOf(complexBarSchema.readonlySet).toEqualTypeOf(); +expectTypeOf(complexBarSchema.readonlyArray).toEqualTypeOf(); +expectTypeOf(complexBarSchema.readonlyTuple).toEqualTypeOf(); +expectTypeOf(complexBarSchema.regExp).toEqualTypeOf(); diff --git a/test-d/screaming-snake-case.ts b/test-d/screaming-snake-case.ts index c515eb396..2c0b21076 100644 --- a/test-d/screaming-snake-case.ts +++ b/test-d/screaming-snake-case.ts @@ -1,23 +1,23 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {ScreamingSnakeCase} from '../index'; const screamingSnakeFromCamel: ScreamingSnakeCase<'fooBar'> = 'FOO_BAR'; -expectType<'FOO_BAR'>(screamingSnakeFromCamel); +expectTypeOf(screamingSnakeFromCamel).toEqualTypeOf<'FOO_BAR'>(); const screamingSnakeFromKebab: ScreamingSnakeCase<'foo-bar'> = 'FOO_BAR'; -expectType<'FOO_BAR'>(screamingSnakeFromKebab); +expectTypeOf(screamingSnakeFromKebab).toEqualTypeOf<'FOO_BAR'>(); const screamingSnakeFromSpace: ScreamingSnakeCase<'foo bar'> = 'FOO_BAR'; -expectType<'FOO_BAR'>(screamingSnakeFromSpace); +expectTypeOf(screamingSnakeFromSpace).toEqualTypeOf<'FOO_BAR'>(); const screamingSnakeFromSnake: ScreamingSnakeCase<'foo_bar'> = 'FOO_BAR'; -expectType<'FOO_BAR'>(screamingSnakeFromSnake); +expectTypeOf(screamingSnakeFromSnake).toEqualTypeOf<'FOO_BAR'>(); const screamingSnakeFromScreamingSnake: ScreamingSnakeCase<'FOO_BAR'> = 'FOO_BAR'; -expectType<'FOO_BAR'>(screamingSnakeFromScreamingSnake); +expectTypeOf(screamingSnakeFromScreamingSnake).toEqualTypeOf<'FOO_BAR'>(); const noScreamingSnakeFromMono: ScreamingSnakeCase<'foobar'> = 'FOOBAR'; -expectType<'FOOBAR'>(noScreamingSnakeFromMono); +expectTypeOf(noScreamingSnakeFromMono).toEqualTypeOf<'FOOBAR'>(); const nonStringFromNonString: ScreamingSnakeCase<[]> = []; -expectType<[]>(nonStringFromNonString); +expectTypeOf(nonStringFromNonString).toEqualTypeOf<[]>(); diff --git a/test-d/set-non-nullable.ts b/test-d/set-non-nullable.ts index 03398b2bf..4b31dbdfc 100644 --- a/test-d/set-non-nullable.ts +++ b/test-d/set-non-nullable.ts @@ -1,18 +1,18 @@ -import {expectNotAssignable, expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {SetNonNullable} from '../index'; // Update one possibly undefined key and one possibly null key to non-nullable. declare const variation1: SetNonNullable<{a: number; b: string | undefined; c: boolean | null}, 'b' | 'c'>; -expectType<{a: number; b: string; c: boolean}>(variation1); +expectTypeOf(variation1).toEqualTypeOf<{a: number; b: string; c: boolean}>(); // Update a key that is possibly null or undefined. declare const variation2: SetNonNullable<{a: number; b: string | null | undefined}, 'b'>; -expectType<{a: number; b: string}>(variation2); +expectTypeOf(variation2).toEqualTypeOf<{a: number; b: string}>(); // Update an optional key. declare const variation3: SetNonNullable<{a: number; b?: string | undefined}, 'b'>; -expectType<{a: number; b?: string}>(variation3); +expectTypeOf(variation3).toEqualTypeOf<{a: number; b?: string}>(); // Fail if type changes even if non-nullable is right. declare const variation4: SetNonNullable<{a: number; b: string | undefined}, 'b'>; -expectNotAssignable<{a: string; b: string}>(variation4); +expectTypeOf(variation4).not.toMatchTypeOf<{a: string; b: string}>(); diff --git a/test-d/set-optional.ts b/test-d/set-optional.ts index 649b4ec07..0affafe8d 100644 --- a/test-d/set-optional.ts +++ b/test-d/set-optional.ts @@ -1,18 +1,18 @@ -import {expectNotAssignable, expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {SetOptional} from '../index'; // Update one required and one optional to optional. declare const variation1: SetOptional<{a: number; b?: string; c: boolean}, 'b' | 'c'>; -expectType<{a: number; b?: string; c?: boolean}>(variation1); +expectTypeOf(variation1).toEqualTypeOf<{a: number; b?: string; c?: boolean}>(); // Update two required to optional. declare const variation2: SetOptional<{a: number; b: string; c: boolean}, 'a' | 'b'>; -expectType<{a?: number; b?: string; c: boolean}>(variation2); +expectTypeOf(variation2).toEqualTypeOf<{a?: number; b?: string; c: boolean}>(); // Three optional remain optional. declare const variation3: SetOptional<{a?: number; b?: string; c?: boolean}, 'a' | 'b' | 'c'>; -expectType<{a?: number; b?: string; c?: boolean}>(variation3); +expectTypeOf(variation3).toEqualTypeOf<{a?: number; b?: string; c?: boolean}>(); // Fail if type changes even if optional is right. declare const variation4: SetOptional<{a: number; b?: string; c: boolean}, 'b' | 'c'>; -expectNotAssignable<{a: boolean; b?: string; c?: boolean}>(variation4); +expectTypeOf(variation4).not.toMatchTypeOf<{a: boolean; b?: string; c?: boolean}>(); diff --git a/test-d/set-required.ts b/test-d/set-required.ts index ef8ea690c..44d8f0333 100644 --- a/test-d/set-required.ts +++ b/test-d/set-required.ts @@ -1,18 +1,18 @@ -import {expectNotAssignable, expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {SetRequired} from '../index'; // Update one required and one optional to required. declare const variation1: SetRequired<{a?: number; b: string; c?: boolean}, 'b' | 'c'>; -expectType<{a?: number; b: string; c: boolean}>(variation1); +expectTypeOf(variation1).toEqualTypeOf<{a?: number; b: string; c: boolean}>(); // Update two optional to required. declare const variation2: SetRequired<{a?: number; b?: string; c?: boolean}, 'a' | 'b'>; -expectType<{a: number; b: string; c?: boolean}>(variation2); +expectTypeOf(variation2).toEqualTypeOf<{a: number; b: string; c?: boolean}>(); // Three required remain required. declare const variation3: SetRequired<{a: number; b: string; c: boolean}, 'a' | 'b' | 'c'>; -expectType<{a: number; b: string; c: boolean}>(variation3); +expectTypeOf(variation3).toEqualTypeOf<{a: number; b: string; c: boolean}>(); // Fail if type changes even if optional is right. declare const variation4: SetRequired<{a?: number; b: string; c?: boolean}, 'b' | 'c'>; -expectNotAssignable<{a?: boolean; b: string; c: boolean}>(variation4); +expectTypeOf(variation4).not.toMatchTypeOf<{a?: boolean; b: string; c: boolean}>(); diff --git a/test-d/set-return-type.ts b/test-d/set-return-type.ts index 18cb7cf56..0636e6d3f 100644 --- a/test-d/set-return-type.ts +++ b/test-d/set-return-type.ts @@ -1,34 +1,36 @@ -import {expectType, expectError} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {SetReturnType} from '../index'; declare const anything: unknown; // Without `thisArg` and without parameters. declare const variation1: SetReturnType<() => void, number>; -expectType<() => number>(variation1); +expectTypeOf(variation1).toEqualTypeOf<() => number>(); variation1.call(anything); // Without `thisArg` and with parameters. declare const variation2: SetReturnType<(foo: string, bar: boolean) => number, void>; -expectType<(foo: string, bar: boolean) => void>(variation2); +expectTypeOf(variation2).toEqualTypeOf<(foo: string, bar: boolean) => void>(); variation2.call(anything, 'foo', true); // With `thisArg` and without parameters. function fn1(this: Date): void {} // eslint-disable-line @typescript-eslint/no-empty-function declare const variation3: SetReturnType; -expectType<(this: Date) => string[]>(variation3); +expectTypeOf(variation3).toEqualTypeOf<(this: Date) => string[]>(); variation3.call(new Date()); -expectError(variation3.call('not-a-date')); +// @ts-expect-error +variation3.call('not-a-date'); // With `thisArg` and with parameters. declare function fn2(this: Date, foo: any, bar: Array<[number]>): any; declare const variation4: SetReturnType; -expectType<(this: Date, foo: any, bar: Array<[number]>) => never>(variation4); +expectTypeOf(variation4).toEqualTypeOf<(this: Date, foo: any, bar: Array<[number]>) => never>(); variation4.call(new Date(), anything, [[4], [7]]); -expectError(variation4.call('not-a-date', anything, [[4], [7]])); +// @ts-expect-error +variation4.call('not-a-date', anything, [[4], [7]]); // Sanity check to the fact that omitting `this: unknown` from the argument list has no effect other than in readability. declare function withExplicitThis(this: unknown, foo: string): number; declare function withImplicitThis(foo: string): number; -expectType(withImplicitThis); -expectType(withExplicitThis); +expectTypeOf(withImplicitThis).toEqualTypeOf(); +expectTypeOf(withExplicitThis).toEqualTypeOf(); diff --git a/test-d/simplify.ts b/test-d/simplify.ts index 524cfa57f..6631a4e0e 100644 --- a/test-d/simplify.ts +++ b/test-d/simplify.ts @@ -1,4 +1,4 @@ -import {expectAssignable, expectNotAssignable, expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {Simplify} from '../index'; type PositionProps = { @@ -13,7 +13,7 @@ type SizeProps = { // Flatten the type output to improve type hints shown in editors. const flattenProps = {top: 120, left: 240, width: 480, height: 600}; -expectType>(flattenProps); +expectTypeOf(flattenProps).toEqualTypeOf>(); // eslint-disable-next-line @typescript-eslint/consistent-type-definitions interface SomeInterface { @@ -33,16 +33,16 @@ const valueAsSimplifiedInterface: Simplify = valueAsLiteral; const valueAsInterface: SomeInterface = valueAsLiteral; declare const a: Simplify; -expectType(a); +expectTypeOf(a).toEqualTypeOf(); // Interface is assignable to its Simplified type (created with Simplify, and by hand) -expectType>(valueAsInterface); -expectType(valueAsInterface); +expectTypeOf(valueAsInterface).toEqualTypeOf>(); +expectTypeOf(valueAsInterface).toEqualTypeOf(); // The following demonstrates one reason a type may be preferred over an interface is that it can be assigned to alternate types. In this example the interface cannot be because it is not sealed and elsewhere a non-string property could be added. -expectAssignable>(valueAsLiteral); -expectAssignable>(valueAsSimplifiedInterface); -expectNotAssignable>(valueAsInterface); // Index signature is missing in interface +expectTypeOf(valueAsLiteral).toMatchTypeOf>(); +expectTypeOf(valueAsSimplifiedInterface).toMatchTypeOf>(); +expectTypeOf(valueAsInterface).not.toMatchTypeOf>(); // Index signature is missing in interface // The following tests should be fixed once we have determined the cause of the bug reported in https://github.com/sindresorhus/type-fest/issues/436 @@ -51,25 +51,25 @@ type SimplifiedFunction = Simplify; // Return '{}' expected 'SomeF declare const someFunction: SimplifiedFunction; -expectNotAssignable(someFunction); +expectTypeOf(someFunction).not.toMatchTypeOf(); // // Should return the original type if it is not simplifiable, like a function. // type SomeFunction = (type: string) => string; -// expectType>((type: string) => type); +// expectTypeOf((type: string) => type).toEqualTypeOf>(); // class SomeClass { -// id: string; +// id: string; -// private readonly code: number; +// private readonly code: number; -// constructor() { -// this.id = 'some-class'; -// this.code = 42; -// } +// constructor() { +// this.id = 'some-class'; +// this.code = 42; +// } -// someMethod() { -// return this.code; -// } +// someMethod() { +// return this.code; +// } // } -// expectType>(new SomeClass()); +// expectTypeOf(new SomeClass()).toEqualTypeOf>(); diff --git a/test-d/snake-case.ts b/test-d/snake-case.ts index d458021f5..751499684 100644 --- a/test-d/snake-case.ts +++ b/test-d/snake-case.ts @@ -1,20 +1,20 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {SnakeCase} from '../index'; const snakeFromCamel: SnakeCase<'fooBar'> = 'foo_bar'; -expectType<'foo_bar'>(snakeFromCamel); +expectTypeOf(snakeFromCamel).toEqualTypeOf<'foo_bar'>(); const snakeFromPascal: SnakeCase<'FooBar'> = 'foo_bar'; -expectType<'foo_bar'>(snakeFromPascal); +expectTypeOf(snakeFromPascal).toEqualTypeOf<'foo_bar'>(); const snakeFromKebab: SnakeCase<'foo-bar'> = 'foo_bar'; -expectType<'foo_bar'>(snakeFromKebab); +expectTypeOf(snakeFromKebab).toEqualTypeOf<'foo_bar'>(); const snakeFromSpace: SnakeCase<'foo bar'> = 'foo_bar'; -expectType<'foo_bar'>(snakeFromSpace); +expectTypeOf(snakeFromSpace).toEqualTypeOf<'foo_bar'>(); const snakeFromSnake: SnakeCase<'foo_bar'> = 'foo_bar'; -expectType<'foo_bar'>(snakeFromSnake); +expectTypeOf(snakeFromSnake).toEqualTypeOf<'foo_bar'>(); const noSnakeFromMono: SnakeCase<'foobar'> = 'foobar'; -expectType<'foobar'>(noSnakeFromMono); +expectTypeOf(noSnakeFromMono).toEqualTypeOf<'foobar'>(); diff --git a/test-d/snake-cased-properties-deep.ts b/test-d/snake-cased-properties-deep.ts index 49b8dc331..a0fda965a 100644 --- a/test-d/snake-cased-properties-deep.ts +++ b/test-d/snake-cased-properties-deep.ts @@ -1,11 +1,11 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {SnakeCasedPropertiesDeep} from '../index'; declare const foo: SnakeCasedPropertiesDeep<{helloWorld: {fooBar: string}}>; -expectType<{hello_world: {foo_bar: string}}>(foo); +expectTypeOf(foo).toEqualTypeOf<{hello_world: {foo_bar: string}}>(); declare const bar: SnakeCasedPropertiesDeep>; -expectType>(bar); +expectTypeOf(bar).toEqualTypeOf>(); // Verify example type User = { @@ -42,4 +42,4 @@ const result: SnakeCasedPropertiesDeep = { }, ], }; -expectType>(result); +expectTypeOf(result).toEqualTypeOf>(); diff --git a/test-d/snake-cased-properties.ts b/test-d/snake-cased-properties.ts index d1f1e8b4d..55f688ee6 100644 --- a/test-d/snake-cased-properties.ts +++ b/test-d/snake-cased-properties.ts @@ -1,8 +1,8 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {SnakeCasedProperties} from '../index'; declare const foo: SnakeCasedProperties<{helloWorld: {fooBar: string}}>; -expectType<{hello_world: {fooBar: string}}>(foo); +expectTypeOf(foo).toEqualTypeOf<{hello_world: {fooBar: string}}>(); // Verify example type User = { @@ -13,4 +13,4 @@ const result: SnakeCasedProperties = { user_id: 1, user_name: 'Tom', }; -expectType>(result); +expectTypeOf(result).toEqualTypeOf>(); diff --git a/test-d/split.ts b/test-d/split.ts index 544ac8d9b..4d6e9403e 100644 --- a/test-d/split.ts +++ b/test-d/split.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {Split} from '../index'; declare function split< @@ -9,22 +9,22 @@ declare function split< const items = 'foo,bar,baz,waldo'; // General use. -expectType<['foo', 'bar', 'baz', 'waldo']>(split(items, ',')); +expectTypeOf(split(items, ',')).toEqualTypeOf<['foo', 'bar', 'baz', 'waldo']>(); // Missing replacement character in original string. -expectType<['foo,bar,baz,waldo']>(split(items, ' ')); +expectTypeOf(split(items, ' ')).toEqualTypeOf<['foo,bar,baz,waldo']>(); // Empty string split (every character). -expectType<[ +expectTypeOf(split(items, '')).toEqualTypeOf<[ 'f', 'o', 'o', ',', 'b', 'a', 'r', ',', 'b', 'a', 'z', ',', 'w', 'a', 'l', 'd', 'o', -]>(split(items, '')); +]>(); // Split single same character. -expectType<['', '']>(split(' ', ' ')); +expectTypeOf(split(' ', ' ')).toEqualTypeOf<['', '']>(); // Split empty string by empty string. -expectType<[]>(split('', '')); +expectTypeOf(split('', '')).toEqualTypeOf<[]>(); // Split empty string by any string. -expectType<['']>(split('', ' ')); +expectTypeOf(split('', ' ')).toEqualTypeOf<['']>(); diff --git a/test-d/spread.ts b/test-d/spread.ts index ea274acc1..bdcf4eab4 100644 --- a/test-d/spread.ts +++ b/test-d/spread.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {Spread} from '../index'; type Foo = { @@ -41,7 +41,7 @@ const bar: Bar = { const foobar = {...foo, ...bar}; -expectType(foobar); +expectTypeOf(foobar).toEqualTypeOf(); const arrayFoo = [1, 2, 3]; const arrayBar = [4, 5, 6]; @@ -49,16 +49,16 @@ const arrayBar = [4, 5, 6]; const arrayFooBar = [...arrayFoo, ...arrayBar]; //=> number[] type ArrayFooBar = Spread; -expectType(arrayFooBar); -expectType(arrayFooBar); +expectTypeOf(arrayFooBar).toEqualTypeOf(); +expectTypeOf(arrayFooBar).toEqualTypeOf(); const stringArray = ['4', '5', '6']; const mixedArrayFooBar = [...arrayFoo, ...stringArray]; //=> (string | number)[] type MixedArrayFooBar = Spread; -expectType(mixedArrayFooBar); -expectType>(mixedArrayFooBar); +expectTypeOf(mixedArrayFooBar).toEqualTypeOf(); +expectTypeOf(mixedArrayFooBar).toEqualTypeOf>(); const tupleFoo: [1, 2, 3] = [1, 2, 3]; const tupleBar: [4, 5, 6] = [4, 5, 6]; @@ -66,17 +66,17 @@ const tupleBar: [4, 5, 6] = [4, 5, 6]; const tupleFooBar = [...tupleFoo, ...tupleBar]; //=> (1 | 2 | 3 | 4 | 5 | 6)[] type TupleFooBar = Spread; -expectType(tupleFooBar); -expectType>(tupleFooBar); +expectTypeOf(tupleFooBar).toEqualTypeOf(); +expectTypeOf(tupleFooBar).toEqualTypeOf>(); const arrayTupleFooBar = [...arrayFoo, ...tupleBar]; //=> number[] type ArrayTupleFooBar = Spread; -expectType(arrayTupleFooBar); -expectType(arrayTupleFooBar); +expectTypeOf(arrayTupleFooBar).toEqualTypeOf(); +expectTypeOf(arrayTupleFooBar).toEqualTypeOf(); const tupleArrayFooBar = [...tupleFoo, ...arrayBar]; //=> number[] type TupleArrayFooBar = Spread; -expectType(tupleArrayFooBar); -expectType(tupleArrayFooBar); +expectTypeOf(tupleArrayFooBar).toEqualTypeOf(); +expectTypeOf(tupleArrayFooBar).toEqualTypeOf(); diff --git a/test-d/string-key-of.ts b/test-d/string-key-of.ts index 0891e87a6..a037e9261 100644 --- a/test-d/string-key-of.ts +++ b/test-d/string-key-of.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {StringKeyOf} from '../index'; declare const foo: StringKeyOf<{ @@ -6,4 +6,4 @@ declare const foo: StringKeyOf<{ stringKey: string; }>; -expectType<'1' | 'stringKey'>(foo); +expectTypeOf(foo).toEqualTypeOf<'1' | 'stringKey'>(); diff --git a/test-d/stringified.ts b/test-d/stringified.ts index f39f17108..216b677b6 100644 --- a/test-d/stringified.ts +++ b/test-d/stringified.ts @@ -1,12 +1,12 @@ -import {expectAssignable, expectNotAssignable, expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {Stringified} from '../index'; declare const stringified: Stringified<{a: number; b: string}>; -expectType<{a: string; b: string}>(stringified); +expectTypeOf(stringified).toEqualTypeOf<{a: string; b: string}>(); type Car = { model: string; speed: number; }; -expectNotAssignable>({model: 'Foo', speed: 101}); -expectAssignable>({model: 'Foo', speed: '101'}); +expectTypeOf<{model: 'Foo'; speed: 101}>().not.toMatchTypeOf>(); +expectTypeOf<{model: 'Foo'; speed: '101'}>().toMatchTypeOf>(); diff --git a/test-d/trim.ts b/test-d/trim.ts index cb4263db9..01938ad9c 100644 --- a/test-d/trim.ts +++ b/test-d/trim.ts @@ -1,10 +1,10 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {Trim} from '../index'; declare function trim(value: S): Trim; -expectType<'foo'>(trim(' foo')); -expectType<'bar'>(trim('bar ')); -expectType<'baz'>(trim(' baz ')); -expectType<'waldo'>(trim(' waldo ')); -expectType<'fr ed'>(trim(' fr ed ')); +expectTypeOf(trim(' foo')).toEqualTypeOf<'foo'>(); +expectTypeOf(trim('bar ')).toEqualTypeOf<'bar'>(); +expectTypeOf(trim(' baz ')).toEqualTypeOf<'baz'>(); +expectTypeOf(trim(' waldo ')).toEqualTypeOf<'waldo'>(); +expectTypeOf(trim(' fr ed ')).toEqualTypeOf<'fr ed'>(); diff --git a/test-d/ts41.ts b/test-d/ts41.ts index cb7ec9bd5..57eb8b97b 100644 --- a/test-d/ts41.ts +++ b/test-d/ts41.ts @@ -1,6 +1,6 @@ // Ensure that TypeScript 4.1 types are available. -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {CamelCase} from '../index'; const camelFromPascal: CamelCase<'FooBar'> = 'fooBar'; -expectType>(camelFromPascal); +expectTypeOf(camelFromPascal).toEqualTypeOf>(); diff --git a/test-d/tsconfig-json.ts b/test-d/tsconfig-json.ts index e6a3b4059..4e729bb42 100644 --- a/test-d/tsconfig-json.ts +++ b/test-d/tsconfig-json.ts @@ -1,13 +1,13 @@ -import {expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {TsConfigJson} from '../index'; const tsConfig: TsConfigJson = {}; -expectType(tsConfig.compileOnSave); -expectType(tsConfig.compilerOptions); -expectType(tsConfig.exclude); -expectType(tsConfig.extends); -expectType(tsConfig.files); -expectType(tsConfig.include); -expectType(tsConfig.references); -expectType(tsConfig.typeAcquisition); +expectTypeOf(tsConfig.compileOnSave).toEqualTypeOf(); +expectTypeOf(tsConfig.compilerOptions).toEqualTypeOf(); +expectTypeOf(tsConfig.exclude).toEqualTypeOf(); +expectTypeOf(tsConfig.extends).toEqualTypeOf(); +expectTypeOf(tsConfig.files).toEqualTypeOf(); +expectTypeOf(tsConfig.include).toEqualTypeOf(); +expectTypeOf(tsConfig.references).toEqualTypeOf(); +expectTypeOf(tsConfig.typeAcquisition).toEqualTypeOf(); diff --git a/test-d/tuple-to-union.ts b/test-d/tuple-to-union.ts index 1393e70f0..cba8e842c 100644 --- a/test-d/tuple-to-union.ts +++ b/test-d/tuple-to-union.ts @@ -1,26 +1,26 @@ -import {expectAssignable, expectNotType, expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {TupleToUnion} from '../index'; const options = ['a', 'b', 'c'] as const; type Options = TupleToUnion; const a: Options = 'a'; -expectAssignable(a); -expectType<'a'>(a); -expectNotType<'b'>(a); -expectNotType<'c'>(a); +expectTypeOf(a).toMatchTypeOf(); +expectTypeOf(a).toEqualTypeOf<'a'>(); +expectTypeOf(a).not.toEqualTypeOf<'b'>(); +expectTypeOf(a).not.toEqualTypeOf<'c'>(); const b: Options = 'b'; -expectAssignable(b); -expectNotType<'a'>(b); -expectType<'b'>(b); -expectNotType<'c'>(b); +expectTypeOf(b).toMatchTypeOf(); +expectTypeOf(b).not.toEqualTypeOf<'a'>(); +expectTypeOf(b).toEqualTypeOf<'b'>(); +expectTypeOf(b).not.toEqualTypeOf<'c'>(); const c: Options = 'c'; -expectAssignable(c); -expectNotType<'a'>(c); -expectNotType<'b'>(c); -expectType<'c'>(c); +expectTypeOf(c).toMatchTypeOf(); +expectTypeOf(c).not.toEqualTypeOf<'a'>(); +expectTypeOf(c).not.toEqualTypeOf<'b'>(); +expectTypeOf(c).toEqualTypeOf<'c'>(); declare const notAnArray: TupleToUnion<[]>; -expectType(notAnArray); +expectTypeOf(notAnArray).toEqualTypeOf(); diff --git a/test-d/union-to-intersection.ts b/test-d/union-to-intersection.ts index 768067ed2..8ba5d05f9 100644 --- a/test-d/union-to-intersection.ts +++ b/test-d/union-to-intersection.ts @@ -1,9 +1,9 @@ -import {expectAssignable} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {UnionToIntersection} from '../index'; declare const intersection1: UnionToIntersection<{a: string} | {b: number}>; -expectAssignable<{a: string; b: number}>(intersection1); +expectTypeOf(intersection1).toMatchTypeOf<{a: string; b: number}>(); // Creates a union of matching properties. declare const intersection2: UnionToIntersection<{a: string} | {b: number} | {a: () => void}>; -expectAssignable<{a: string | (() => void); b: number}>(intersection2); +expectTypeOf(intersection2).toMatchTypeOf<{a: string | (() => void); b: number}>(); diff --git a/test-d/value-of.ts b/test-d/value-of.ts index 648a48683..6ff3cc9ef 100644 --- a/test-d/value-of.ts +++ b/test-d/value-of.ts @@ -1,12 +1,12 @@ -import {expectAssignable, expectNotAssignable, expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {ValueOf} from '../index'; const value: ValueOf<{a: 1; b: 2; c: 3}> = 3; const valueRestricted: ValueOf<{a: 1; b: 2; c: 3}, 'a'> = 1; -expectAssignable<1 | 2 | 3>(value); -expectNotAssignable<4>(value); +expectTypeOf(value).toMatchTypeOf<1 | 2 | 3>(); +expectTypeOf(value).not.toMatchTypeOf<4>(); -expectType<1>(valueRestricted); -expectNotAssignable<2>(valueRestricted); -expectNotAssignable<4>(valueRestricted); +expectTypeOf(valueRestricted).toEqualTypeOf<1>(); +expectTypeOf(valueRestricted).not.toMatchTypeOf<2>(); +expectTypeOf(valueRestricted).not.toMatchTypeOf<4>(); diff --git a/test-d/writable.ts b/test-d/writable.ts index 9c3211fed..c490c8b4f 100644 --- a/test-d/writable.ts +++ b/test-d/writable.ts @@ -1,4 +1,4 @@ -import {expectNotAssignable, expectType} from 'tsd'; +import {expectTypeOf} from 'expect-type'; import type {Writable} from '../index'; type Foo = { @@ -13,16 +13,16 @@ ab2.a = 2; // Update one writable and one readonly to writable, leaving one property unaffected. declare const variation1: Writable<{readonly a: number; b: string; readonly c: boolean}, 'b' | 'c'>; -expectType<{readonly a: number; b: string; c: boolean}>(variation1); +expectTypeOf(variation1).toEqualTypeOf<{readonly a: number; b: string; c: boolean}>(); // Update two readonly to writable, leaving one property unaffected. declare const variation2: Writable<{readonly a: number; readonly b: string; readonly c: boolean}, 'a' | 'b'>; -expectType<{a: number; b: string; readonly c: boolean}>(variation2); +expectTypeOf(variation2).toEqualTypeOf<{a: number; b: string; readonly c: boolean}>(); // Three writable remain writable. declare const variation3: Writable<{a: number; b: string; c: boolean}, 'a' | 'b' | 'c'>; -expectType<{a: number; b: string; c: boolean}>(variation3); +expectTypeOf(variation3).toEqualTypeOf<{a: number; b: string; c: boolean}>(); // Check if type changes raise an error even if readonly and writable are applied correctly. declare const variation4: Writable<{readonly a: number; b: string; readonly c: boolean}, 'b' | 'c'>; -expectNotAssignable<{readonly a: boolean; b: string; c: boolean}>(variation4); +expectTypeOf(variation4).not.toMatchTypeOf<{readonly a: boolean; b: string; c: boolean}>(); diff --git a/tsconfig.json b/tsconfig.json index d16e1d114..f319ad747 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,4 @@ "DOM" ] }, - "exclude": [ - "test-d/**/*" - ] }