diff --git a/package.json b/package.json index 5e63bde08..7511664d9 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ "node": ">=16" }, "scripts": { - "test:set-parameter-type": "tsc --noEmit test-d/set-parameter-type", "test:source-files-extension": "node script/test/source-files-extension.js", "test:tsc": "tsc", "test:tsd": "tsd", diff --git a/test-d/abstract-class.ts b/test-d/abstract-class.ts index f9816a066..3727ed450 100644 --- a/test-d/abstract-class.ts +++ b/test-d/abstract-class.ts @@ -1,4 +1,4 @@ -import {expectError, expectAssignable, expectNotAssignable, expectType} from 'tsd'; +import {expectAssignable, expectNotAssignable, expectType} from 'tsd'; import type {AbstractConstructor, AbstractClass, IsAny} from '../index'; abstract class Foo { @@ -47,7 +47,8 @@ function assertWithBar() { } functionReceivingAbsClass(Foo); -expectError(functionReceivingAbsClass(Foo)); +// @ts-expect-error +functionReceivingAbsClass(Foo); assertWithBar(); expectAssignable>(Bar); @@ -56,7 +57,8 @@ expectAssignable>(Bar); // Prototype test expectAssignable<{barMethod(): void}>(Bar.prototype); expectNotAssignable<{fooMethod(): void}>(Bar.prototype); -expectError(new CorrectConcreteExtendedBar(12)); +// @ts-expect-error +const _a = new CorrectConcreteExtendedBar(12); expectAssignable<{barMethod(): void}>(new CorrectConcreteExtendedBar(12, 15)); // /Prototype test diff --git a/test-d/async-return-type.ts b/test-d/async-return-type.ts index 7c241bcc0..053b5c6a8 100644 --- a/test-d/async-return-type.ts +++ b/test-d/async-return-type.ts @@ -7,6 +7,7 @@ async function asyncFunction(): Promise { type Value = AsyncReturnType; -const value = await asyncFunction(); -expectType(value); -expectNotAssignable(value); +asyncFunction().then(value => { // eslint-disable-line unicorn/prefer-top-level-await, @typescript-eslint/no-floating-promises + expectType(value); + expectNotAssignable(value); +}); diff --git a/test-d/asyncify.ts b/test-d/asyncify.ts index 7eab01472..c8164539a 100644 --- a/test-d/asyncify.ts +++ b/test-d/asyncify.ts @@ -1,4 +1,4 @@ -import {expectType, expectError} from 'tsd'; +import {expectType} from 'tsd'; import type {Asyncify} from '../index'; declare function getFooSync(name: string): RegExp; @@ -16,4 +16,7 @@ expectType(getFooAsync2); declare const getFooWithThisArgumentAsync1: Asyncify; const callResult = getFooWithThisArgumentAsync1.call(new Date(), 'foo'); expectType>(callResult); -expectError(getFooWithThisArgumentAsync1.call('not-date', 'foo')); + +// @ts-expect-error +// eslint-disable-next-line @typescript-eslint/no-floating-promises +getFooWithThisArgumentAsync1.call('not-date', 'foo'); diff --git a/test-d/class.ts b/test-d/class.ts index b944ae714..fc2f5252d 100644 --- a/test-d/class.ts +++ b/test-d/class.ts @@ -1,4 +1,4 @@ -import {expectAssignable, expectError, expectNotAssignable, expectType} from 'tsd'; +import {expectAssignable, expectNotAssignable, expectType} from 'tsd'; import type {Class, Constructor, IsAny} from '../index'; class Foo { @@ -15,7 +15,8 @@ function function_(Cls: Constructor): Foo { } function function2(Cls: Constructor): Foo { - expectError(new Cls(1, '')); + // @ts-expect-error + const _ = new Cls(1, ''); return new Cls(1, 2); } @@ -52,7 +53,8 @@ expectType>(false); expectType(Position.prototype); // /Prototype test -expectError(new Position(17)); +// @ts-expect-error +const _a = new Position(17); expectAssignable(new Position(17, 34)); // Prototype test with type parameter diff --git a/test-d/distributed-omit.ts b/test-d/distributed-omit.ts index bbe35a366..c53ecba04 100644 --- a/test-d/distributed-omit.ts +++ b/test-d/distributed-omit.ts @@ -1,4 +1,4 @@ -import {expectType, expectError} from 'tsd'; +import {expectType} from 'tsd'; import type {DistributedOmit, Except} from '../index'; // When passing a non-union type, and @@ -36,9 +36,8 @@ type Example2 = { b: string; }; -expectError(() => { - type Actual4 = DistributedOmit; -}); +// @ts-expect-error +type Actual4 = DistributedOmit; // When passing a union type, and // omitting keys that are present in some union members. @@ -72,6 +71,8 @@ declare const omittedUnion: OmittedUnion; if (omittedUnion.discriminant === 'A') { expectType<{discriminant: 'A'; a: number}>(omittedUnion); - expectError(omittedUnion.foo); - expectError(omittedUnion.bar); + // @ts-expect-error + const _a: unknown = omittedUnion.foo; + // @ts-expect-error + const _b: unknown = omittedUnion.bar; } diff --git a/test-d/distributed-pick.ts b/test-d/distributed-pick.ts index 5fc5b01e2..93f7bcf2b 100644 --- a/test-d/distributed-pick.ts +++ b/test-d/distributed-pick.ts @@ -1,4 +1,4 @@ -import {expectType, expectError} from 'tsd'; +import {expectType} from 'tsd'; import type {DistributedPick} from '../index'; // When passing a non-union type, and @@ -36,9 +36,8 @@ type Example2 = { b: string; }; -expectError(() => { - type Actual4 = DistributedPick; -}); +// @ts-expect-error +type Actual4 = DistributedPick; // When passing a union type, and // picking keys that are present in some union members. @@ -72,6 +71,8 @@ declare const pickedUnion: PickedUnion; if (pickedUnion.discriminant === 'A') { expectType<{discriminant: 'A'; a: number}>(pickedUnion); - expectError(pickedUnion.foo); - expectError(pickedUnion.bar); + // @ts-expect-error + const _foo = pickedUnion.foo; // eslint-disable-line @typescript-eslint/no-unsafe-assignment + // @ts-expect-error + const _bar = pickedUnion.bar; // eslint-disable-line @typescript-eslint/no-unsafe-assignment } diff --git a/test-d/empty-object.ts b/test-d/empty-object.ts index 14d5eeaa8..9bb6ff4e2 100644 --- a/test-d/empty-object.ts +++ b/test-d/empty-object.ts @@ -1,4 +1,4 @@ -import {expectAssignable, expectError, expectType} from 'tsd'; +import {expectAssignable, expectType} from 'tsd'; import type {EmptyObject, IsEmptyObject} from '../index'; declare let foo: EmptyObject; @@ -6,12 +6,18 @@ 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 = {}); +// @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 = {}; expectType>(true); expectType>(true); @@ -23,7 +29,8 @@ expectType void>>(false); type Union = EmptyObject | {id: number}; const bar: Union = {}; -expectError(bar.id); +// @ts-expect-error +const _a: unknown = bar.id; const baz: Union = {id: 42}; expectType<{id: number}>(baz); diff --git a/test-d/exact.ts b/test-d/exact.ts index 14608aafc..bd504260b 100644 --- a/test-d/exact.ts +++ b/test-d/exact.ts @@ -1,4 +1,3 @@ -import {expectError} from 'tsd'; import type {Exact, Opaque} from '../index'; { // Spec - string type @@ -398,7 +397,8 @@ import type {Exact, Opaque} from '../index'; const function_ = >(arguments_: T) => arguments_; function_({a: 1 as TaggedNumber}); - expectError(function_({a: 1 as TaggedNumber, b: true})); + // @ts-expect-error + function_({a: 1 as TaggedNumber, b: true}); } // Spec - special test case for deep optional union diff --git a/test-d/except.ts b/test-d/except.ts index c2ee3b3c9..cf2d1233e 100644 --- a/test-d/except.ts +++ b/test-d/except.ts @@ -1,9 +1,10 @@ -import {expectType, expectError} from 'tsd'; +import {expectType} from 'tsd'; import type {Except} from '../index'; declare const except: Except<{a: number; b: string}, 'b'>; expectType<{a: number}>(except); -expectError(except.b); +// @ts-expect-error +const _a: unknown = except.b; const nonStrict = { a: 1, @@ -14,9 +15,8 @@ const nonStrictAssignment: typeof except = nonStrict; // No error declare const strictExcept: Except<{a: number; b: string}, 'b', {requireExactProps: true}>; -expectError(() => { - const strictAssignment: typeof strictExcept = nonStrict; -}); +// @ts-expect-error +const strictAssignment: typeof strictExcept = nonStrict; // Generic properties type Example = { diff --git a/test-d/if-any.ts b/test-d/if-any.ts index 972cdbc60..f5a5952ab 100644 --- a/test-d/if-any.ts +++ b/test-d/if-any.ts @@ -1,4 +1,4 @@ -import {expectError, expectType} from 'tsd'; +import {expectType} from 'tsd'; import type {IfAny} from '../index'; declare const _any: any; @@ -10,4 +10,5 @@ expectType>('T'); expectType>('F'); // Missing generic parameter -expectError(_any); +// @ts-expect-error +type A = IfAny; diff --git a/test-d/if-never.ts b/test-d/if-never.ts index 724d9d831..bf9010263 100644 --- a/test-d/if-never.ts +++ b/test-d/if-never.ts @@ -1,8 +1,6 @@ -import {expectError, expectType} from 'tsd'; +import {expectType} from 'tsd'; import type {IfNever} from '../index'; -declare const _never: never; - // `IfNever` should return `true`/`false` if only `T` is specified expectType>(true); expectType>(false); @@ -10,4 +8,5 @@ expectType>('T'); expectType>('F'); // Missing generic parameter -expectError(_never); +// @ts-expect-error +type A = IfNever; diff --git a/test-d/if-unknown.ts b/test-d/if-unknown.ts index a11a5ce6f..b89aeb547 100644 --- a/test-d/if-unknown.ts +++ b/test-d/if-unknown.ts @@ -1,8 +1,6 @@ -import {expectError, expectType} from 'tsd'; +import {expectType} from 'tsd'; import type {IfUnknown} from '../index'; -declare const _unknown: unknown; - // `IfUnknown` should return `true`/`false` if only `T` is specified expectType>(true); expectType>(false); @@ -10,4 +8,5 @@ expectType>('T'); expectType>('F'); // Missing generic parameter -expectError(_unknown); +// @ts-expect-error +type A = IfUnknown; diff --git a/test-d/includes.ts b/test-d/includes.ts index e3d3b5de0..78a5adb2b 100644 --- a/test-d/includes.ts +++ b/test-d/includes.ts @@ -1,4 +1,4 @@ -import {expectError, expectType} from 'tsd'; +import {expectType} from 'tsd'; import type {Includes} from '../index'; const includesEmptyArray: Includes<[], 'abc'> = false; @@ -38,18 +38,20 @@ expectType(nullIncludesUndefined); const nullIncludesNullPass: Includes<[null], null> = true; expectType(nullIncludesNullPass); -declare const anything: any; - // Verify that incorrect usage of `Includes` produces an error. // Missing all generic parameters. -expectError(anything); +// @ts-expect-error +type A0 = Includes; // Missing `Item` generic parameter. -expectError>(anything); +// @ts-expect-error +type A1 = Includes<['my', 'array', 'has', 'stuff']>; // Value generic parameter is a string not an array. -expectError>(anything); +// @ts-expect-error +type A2 = Includes<'why a string?', 5>; // Value generic parameter is an object not an array. -expectError>(anything); +// @ts-expect-error +type A3 = Includes<{key: 'value'}, 7>; diff --git a/test-d/int-range.ts b/test-d/int-range.ts index a1ce016c4..52c4f996c 100644 --- a/test-d/int-range.ts +++ b/test-d/int-range.ts @@ -1,4 +1,4 @@ -import {expectType, expectError, expectAssignable} from 'tsd'; +import {expectType, expectAssignable} from 'tsd'; import type {IntRange} from '../source/int-range'; declare const test: IntRange<0, 5>; diff --git a/test-d/internal/require-none.ts b/test-d/internal/require-none.ts index 75ccdea30..45382741c 100644 --- a/test-d/internal/require-none.ts +++ b/test-d/internal/require-none.ts @@ -1,4 +1,4 @@ -import {expectAssignable, expectNotAssignable, expectType} from 'tsd'; +import {expectAssignable, expectNotAssignable} from 'tsd'; import {type RequireNone} from '../../source/internal'; type NoneAllowed = RequireNone<'foo' | 'bar'>; diff --git a/test-d/is-any.ts b/test-d/is-any.ts index 97ca8e17f..0081f9774 100644 --- a/test-d/is-any.ts +++ b/test-d/is-any.ts @@ -1,4 +1,4 @@ -import {expectError, expectType} from 'tsd'; +import {expectType} from 'tsd'; import type {IsAny} from '../index'; declare const anything: any; @@ -16,4 +16,5 @@ expectType>(false); expectType>(false); // Missing generic parameter -expectError(anything); +// @ts-expect-error +type A = IsAny; diff --git a/test-d/is-equal.ts b/test-d/is-equal.ts index 242798d01..f2dcd1bbb 100644 --- a/test-d/is-equal.ts +++ b/test-d/is-equal.ts @@ -1,4 +1,4 @@ -import {expectError, expectType} from 'tsd'; +import {expectType} from 'tsd'; import type {IsEqual} from '../index'; const notEqualNumberAndString: IsEqual = false; @@ -19,10 +19,10 @@ expectType(notEqualAnyAndNever); const notEqualArrayOfAnyAndArrayOfNever: IsEqual<[any], [never]> = false; expectType(notEqualArrayOfAnyAndArrayOfNever); -declare const anything: any; - // Missing all generic parameters. -expectError(anything); +// @ts-expect-error +type A = IsEqual; // Missing `Y` generic parameter. -expectError>(anything); +// @ts-expect-error +type B = IsEqual; diff --git a/test-d/is-literal.ts b/test-d/is-literal.ts index d10fb0239..b37337368 100644 --- a/test-d/is-literal.ts +++ b/test-d/is-literal.ts @@ -1,4 +1,4 @@ -import {expectError, expectType} from 'tsd'; +import {expectType} from 'tsd'; import type { IsLiteral, IsStringLiteral, @@ -54,11 +54,14 @@ expectType>(false); expectType>(true); expectType>(false); -declare const anything: any; - // Missing generic parameter -expectError(anything); -expectError(anything); -expectError(anything); -expectError(anything); -expectError(anything); +// @ts-expect-error +type A0 = IsLiteral; +// @ts-expect-error +type A1 = IsStringLiteral; +// @ts-expect-error +type A2 = IsNumericLiteral; +// @ts-expect-error +type A3 = IsBooleanLiteral; +// @ts-expect-error +type A4 = IsSymbolLiteral; diff --git a/test-d/is-never.ts b/test-d/is-never.ts index 76e7e5c6a..6388de8c9 100644 --- a/test-d/is-never.ts +++ b/test-d/is-never.ts @@ -1,4 +1,4 @@ -import {expectError, expectType} from 'tsd'; +import {expectType} from 'tsd'; import type {IsNever} from '../index'; declare const _never: never; @@ -16,4 +16,5 @@ expectType>(false); expectType>(false); // Missing generic parameter -expectError(_never); +// @ts-expect-error +type A = IsNever; diff --git a/test-d/is-unknown.ts b/test-d/is-unknown.ts index 6ae78589c..93e7d1ef6 100644 --- a/test-d/is-unknown.ts +++ b/test-d/is-unknown.ts @@ -1,4 +1,4 @@ -import {expectError, expectType} from 'tsd'; +import {expectType} from 'tsd'; import type {IsUnknown} from '../index'; declare const _unknown: unknown; @@ -16,4 +16,5 @@ expectType>(false); expectType>(false); // Missing generic parameter -expectError(_unknown); +// @ts-expect-error +type A = IsUnknown; diff --git a/test-d/merge-deep.ts b/test-d/merge-deep.ts index db8571653..71f83bb38 100644 --- a/test-d/merge-deep.ts +++ b/test-d/merge-deep.ts @@ -1,4 +1,4 @@ -import {expectError, expectType} from 'tsd'; +import {expectType} from 'tsd'; import type {MergeDeep, MergeDeepOptions} from '../index'; // Test helper. @@ -70,7 +70,8 @@ const mergedClass = mergeDeep({ClassConstructor: ClassA}, {ClassConstructor: Cla const instance = new mergedClass.ClassConstructor(); expectType<{ClassConstructor: typeof ClassB}>(mergedClass); expectType(instance); -expectError(instance.bar); +// @ts-expect-error +const _a: unknown = instance.bar; // Should merge simple types type Foo = {foo: string; fooBar: unknown; items: string[]}; diff --git a/test-d/merge.ts b/test-d/merge.ts index c351db52e..dc95cded6 100644 --- a/test-d/merge.ts +++ b/test-d/merge.ts @@ -1,4 +1,4 @@ -import {expectError, expectType} from 'tsd'; +import {expectType} from 'tsd'; import type {Merge} from '../index'; type Foo = { @@ -50,12 +50,13 @@ expectType<{ 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 = { diff --git a/test-d/omit-deep.ts b/test-d/omit-deep.ts index de5f6dd46..1b241e688 100644 --- a/test-d/omit-deep.ts +++ b/test-d/omit-deep.ts @@ -1,5 +1,5 @@ import {expectType} from 'tsd'; -import type {OmitDeep, Simplify} from '../index'; +import type {OmitDeep} from '../index'; declare class ClassA { a: string; diff --git a/test-d/opaque.ts b/test-d/opaque.ts index 163d3c902..cb5b1f204 100644 --- a/test-d/opaque.ts +++ b/test-d/opaque.ts @@ -1,4 +1,4 @@ -import {expectAssignable, expectError, expectNotAssignable, expectNotType, expectType} from 'tsd'; +import {expectAssignable, expectNotAssignable, expectNotType, expectType} from 'tsd'; import type {Opaque, UnwrapOpaque, Tagged, GetTagMetadata, UnwrapTagged, InvariantOf, SnakeCasedPropertiesDeep} from '../index'; type Value = Opaque; @@ -127,7 +127,8 @@ type JsonOf = Tagged; expectType(JSON.parse('43') as GetTagMetadata, 'JSON'>); // It's a type error to try to get the metadata for a tag that doesn't exist on a type. -expectError('' as GetTagMetadata); +// @ts-expect-error +const _a = '' as GetTagMetadata; // Tagged types should be covariant in their metadata type expectAssignable>('' as JsonOf<42>); diff --git a/test-d/override-properties.ts b/test-d/override-properties.ts index 054e3c6c8..e920ee199 100644 --- a/test-d/override-properties.ts +++ b/test-d/override-properties.ts @@ -1,4 +1,4 @@ -import {expectError, expectType} from 'tsd'; +import {expectType} from 'tsd'; import type {OverrideProperties} from '../source/override-properties'; type Foo = { @@ -9,10 +9,8 @@ type Foo = { const fixture: OverrideProperties = {a: 1, b: 2}; expectType<{a: number; b: number}>(fixture); -expectError(() => { - type Bar = OverrideProperties; -}); +// @ts-expect-error +type Bar = OverrideProperties; -expectError(() => { - type Bar = OverrideProperties; -}); +// @ts-expect-error +type Bar = OverrideProperties; diff --git a/test-d/package-json.ts b/test-d/package-json.ts index c6f188d21..717404921 100644 --- a/test-d/package-json.ts +++ b/test-d/package-json.ts @@ -1,4 +1,4 @@ -import {expectType, expectAssignable, expectNotAssignable, expectError} from 'tsd'; +import {expectType, expectAssignable, expectNotAssignable} from 'tsd'; import type {PackageJson, LiteralUnion, JsonObject} from '../index'; const packageJson: PackageJson = {}; @@ -106,8 +106,10 @@ expectAssignable({ // 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}}); diff --git a/test-d/partial-deep.ts b/test-d/partial-deep.ts index 2560d85ea..3a5c6dee3 100644 --- a/test-d/partial-deep.ts +++ b/test-d/partial-deep.ts @@ -1,4 +1,4 @@ -import {expectType, expectError, expectAssignable} from 'tsd'; +import {expectType, expectAssignable} from 'tsd'; import type {PartialDeep} from '../index'; class ClassA { @@ -32,7 +32,8 @@ const foo = { let partialDeepFoo: PartialDeep = foo; -expectError(expectType>(partialDeepFoo)); +// @ts-expect-error +expectType>(partialDeepFoo); const partialDeepBar: PartialDeep = foo.bar; expectType(partialDeepFoo.bar); // Check for constructor @@ -79,7 +80,8 @@ const partialDeepNoRecurseIntoArraysFoo: PartialDeep = foo; // Check that `{recurseIntoArrays: true}` behaves as intended expectType>(partialDeepFoo); // These are mostly the same checks as before, but the array/tuple types are different. -expectError(expectType>(partialDeepNoRecurseIntoArraysFoo)); +// @ts-expect-error +expectType>(partialDeepNoRecurseIntoArraysFoo); const partialDeepNoRecurseIntoArraysBar: PartialDeep = foo.bar; expectType(partialDeepNoRecurseIntoArraysFoo.bar); expectType<((_: string) => void) | undefined>(partialDeepNoRecurseIntoArraysBar.function); diff --git a/test-d/readonly-deep.ts b/test-d/readonly-deep.ts index a791f79b7..dee1853ce 100644 --- a/test-d/readonly-deep.ts +++ b/test-d/readonly-deep.ts @@ -1,4 +1,4 @@ -import {expectType, expectError, expectAssignable} from 'tsd'; +import {expectType, expectAssignable} from 'tsd'; import type {Opaque, tag} from '../source/opaque'; import type {ReadonlyDeep, ReadonlyObjectDeep} from '../source/readonly-deep'; import type {JsonValue} from '../source/basic'; @@ -75,7 +75,8 @@ expectType(readonlyData.constructor); const instance = new readonlyData.constructor(); instance.foo = 2; // Constructor is not made readonly -expectError(readonlyData.string = 'bar'); +// @ts-expect-error +readonlyData.string = 'bar'; expectType<{readonly foo: string}>(readonlyData.object); expectType(readonlyData.string); expectType(readonlyData.number); diff --git a/test-d/readonly-tuple.ts b/test-d/readonly-tuple.ts index 06527b141..2a0c688e2 100644 --- a/test-d/readonly-tuple.ts +++ b/test-d/readonly-tuple.ts @@ -1,4 +1,4 @@ -import {expectAssignable, expectError, expectNotAssignable} from 'tsd'; +import {expectAssignable, expectNotAssignable} from 'tsd'; import type {ReadonlyTuple} from '../index'; type TupleOfThreeStrings = ReadonlyTuple; @@ -12,5 +12,7 @@ expectNotAssignable(['a', 'b', 'c', 'd']); declare const test: TupleOfThreeStrings; -expectError(test.push); -expectError(test[2] = 'a'); +// @ts-expect-error +const _a: unknown = test.push; +// @ts-expect-error +test[2] = 'a'; diff --git a/test-d/require-all-or-none.ts b/test-d/require-all-or-none.ts index 1adcc9536..84204b6c5 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 {expectAssignable} from 'tsd'; 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); diff --git a/test-d/require-at-least-one.ts b/test-d/require-at-least-one.ts index 66ef26538..757b72239 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 {expectAssignable} from 'tsd'; import type {RequireAtLeastOne} from '../index'; type SystemMessages = { @@ -23,9 +23,12 @@ 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; diff --git a/test-d/require-exactly-one.ts b/test-d/require-exactly-one.ts index 5180b5554..a11679768 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 {expectAssignable} from 'tsd'; import type {RequireExactlyOne} from '../index'; type SystemMessages = { @@ -16,9 +16,12 @@ 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)); +// @ts-expect-error +expectAssignable<{a: number; b: number}>(oneWithoutKeys); diff --git a/test-d/set-return-type.ts b/test-d/set-return-type.ts index a5c460bf3..93c21fc24 100644 --- a/test-d/set-return-type.ts +++ b/test-d/set-return-type.ts @@ -1,4 +1,4 @@ -import {expectType, expectError} from 'tsd'; +import {expectType} from 'tsd'; import type {SetReturnType} from '../index'; declare const anything: unknown; @@ -18,14 +18,16 @@ function function1(this: Date): void {} // eslint-disable-line @typescript-eslin declare const variation3: SetReturnType; expectType<(this: Date) => string[]>(variation3); 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 function2(this: Date, foo: any, bar: Array<[number]>): any; declare const variation4: SetReturnType; expectType<(this: Date, foo: any, bar: Array<[number]>) => never>(variation4); 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; diff --git a/test-d/single-key-object.ts b/test-d/single-key-object.ts index cc06c0829..4c170d597 100644 --- a/test-d/single-key-object.ts +++ b/test-d/single-key-object.ts @@ -1,12 +1,14 @@ -import {expectNever, expectError, expectAssignable} from 'tsd'; +import {expectNever, expectAssignable} from 'tsd'; import type {SingleKeyObject} from '../index'; const test = (_: SingleKeyObject): void => {}; // eslint-disable-line @typescript-eslint/no-empty-function test({key: 'value'}); -expectError(test({})); -expectError(test({key: 'value', otherKey: 'other value'})); +// @ts-expect-error +test({}); +// @ts-expect-error +test({key: 'value', otherKey: 'other value'}); declare const validObject: SingleKeyObject<{key: string}>; expectAssignable<{key: string}>(validObject); diff --git a/test-d/unknown-array.ts b/test-d/unknown-array.ts index 37e379442..e35a98537 100644 --- a/test-d/unknown-array.ts +++ b/test-d/unknown-array.ts @@ -1,4 +1,4 @@ -import {expectAssignable, expectError, expectNotAssignable, expectType} from 'tsd'; +import {expectAssignable, expectNotAssignable, expectType} from 'tsd'; import type {UnknownArray} from '../index'; declare const foo: readonly []; diff --git a/test-d/unknown-record.ts b/test-d/unknown-record.ts index bab55eb52..d2bb9c18e 100644 --- a/test-d/unknown-record.ts +++ b/test-d/unknown-record.ts @@ -1,4 +1,4 @@ -import {expectAssignable, expectError, expectType} from 'tsd'; +import {expectAssignable, expectType} from 'tsd'; import type {UnknownRecord} from '../index'; declare let foo: UnknownRecord; @@ -8,8 +8,11 @@ expectAssignable(foo = {}); expectAssignable(foo = {bar: 'baz'}); expectAssignable(foo = {bar: {baz: 'hello'}}); -expectError(foo = []); -expectError(foo = 42); -expectError(foo = null); +// @ts-expect-error +foo = []; +// @ts-expect-error +foo = 42; +// @ts-expect-error +foo = null; expectType(foo['bar']); diff --git a/test-d/writable-deep.ts b/test-d/writable-deep.ts index dc62727c6..d1694d4eb 100644 --- a/test-d/writable-deep.ts +++ b/test-d/writable-deep.ts @@ -1,4 +1,4 @@ -import {expectType, expectError, expectAssignable} from 'tsd'; +import {expectType, expectAssignable} from 'tsd'; import type {JsonValue, Opaque, ReadonlyDeep, WritableDeep} from '../index'; import type {WritableObjectDeep} from '../source/writable-deep'; import {type tag} from '../source/opaque'; @@ -64,7 +64,8 @@ const data = { const readonlyData: ReadonlyDeep = data; let writableData: WritableDeep; -expectError(writableData = readonlyData); +// @ts-expect-error +writableData = readonlyData; // eslint-disable-line prefer-const writableData.fn('foo'); diff --git a/tsconfig.json b/tsconfig.json index 966ec6620..2cbea234b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,6 +2,7 @@ /// "extends": "@sindresorhus/tsconfig", "compilerOptions": { "noEmit": true, + "noUnusedLocals": false, // Allow unused variables in test-d/*.ts files "target": "ES2021", // Node.js 16 "lib": [ "ES2021", @@ -19,7 +20,6 @@ "strict": true, "noImplicitReturns": true, "noImplicitOverride": true, - "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, // "noUncheckedIndexedAccess": true, // TODO: Enable. @@ -27,6 +27,8 @@ "useDefineForClassFields": true, }, "exclude": [ - "test-d/**/*" + // Ignore `ConditionalKeys` and `WriteableDeep` error temporarily, remove when #831 and #833 are fixed. + "test-d/conditional-keys.ts", + "test-d/writable-deep.ts", ] }