Skip to content

Commit

Permalink
Run tsc on all files (#842)
Browse files Browse the repository at this point in the history
  • Loading branch information
Emiyaaaaa committed Apr 2, 2024
1 parent fa1c3f3 commit dfa0611
Show file tree
Hide file tree
Showing 39 changed files with 180 additions and 130 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions test-d/abstract-class.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -47,7 +47,8 @@ function assertWithBar() {
}

functionReceivingAbsClass(Foo);
expectError(functionReceivingAbsClass<Bar>(Foo));
// @ts-expect-error
functionReceivingAbsClass<Bar>(Foo);
assertWithBar();

expectAssignable<AbstractConstructor<{barMethod(): void}, []>>(Bar);
Expand All @@ -56,7 +57,8 @@ expectAssignable<AbstractClass<{barMethod(): void}, []>>(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

Expand Down
7 changes: 4 additions & 3 deletions test-d/async-return-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ async function asyncFunction(): Promise<number> {

type Value = AsyncReturnType<typeof asyncFunction>;

const value = await asyncFunction();
expectType<Value>(value);
expectNotAssignable<string>(value);
asyncFunction().then(value => { // eslint-disable-line unicorn/prefer-top-level-await, @typescript-eslint/no-floating-promises
expectType<Value>(value);
expectNotAssignable<string>(value);
});
7 changes: 5 additions & 2 deletions test-d/asyncify.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expectType, expectError} from 'tsd';
import {expectType} from 'tsd';
import type {Asyncify} from '../index';

declare function getFooSync(name: string): RegExp;
Expand All @@ -16,4 +16,7 @@ expectType<typeof getFooAsync1>(getFooAsync2);
declare const getFooWithThisArgumentAsync1: Asyncify<typeof getFooWithThisArgumentSync>;
const callResult = getFooWithThisArgumentAsync1.call(new Date(), 'foo');
expectType<Promise<RegExp>>(callResult);
expectError(getFooWithThisArgumentAsync1.call('not-date', 'foo'));

// @ts-expect-error
// eslint-disable-next-line @typescript-eslint/no-floating-promises
getFooWithThisArgumentAsync1.call('not-date', 'foo');
8 changes: 5 additions & 3 deletions test-d/class.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -15,7 +15,8 @@ function function_(Cls: Constructor<Foo>): Foo {
}

function function2(Cls: Constructor<Foo, [number, number]>): Foo {
expectError(new Cls(1, ''));
// @ts-expect-error
const _ = new Cls(1, '');
return new Cls(1, 2);
}

Expand Down Expand Up @@ -52,7 +53,8 @@ expectType<IsAny<typeof Bar['prototype']>>(false);
expectType<PositionProperties>(Position.prototype);
// /Prototype test

expectError(new Position(17));
// @ts-expect-error
const _a = new Position(17);
expectAssignable<PositionProperties>(new Position(17, 34));

// Prototype test with type parameter
Expand Down
13 changes: 7 additions & 6 deletions test-d/distributed-omit.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -36,9 +36,8 @@ type Example2 = {
b: string;
};

expectError(() => {
type Actual4 = DistributedOmit<Example2, 'c'>;
});
// @ts-expect-error
type Actual4 = DistributedOmit<Example2, 'c'>;

// When passing a union type, and
// omitting keys that are present in some union members.
Expand Down Expand Up @@ -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;
}
13 changes: 7 additions & 6 deletions test-d/distributed-pick.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -36,9 +36,8 @@ type Example2 = {
b: string;
};

expectError(() => {
type Actual4 = DistributedPick<Example2, 'c'>;
});
// @ts-expect-error
type Actual4 = DistributedPick<Example2, 'c'>;

// When passing a union type, and
// picking keys that are present in some union members.
Expand Down Expand Up @@ -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
}
23 changes: 15 additions & 8 deletions test-d/empty-object.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import {expectAssignable, expectError, expectType} from 'tsd';
import {expectAssignable, expectType} from 'tsd';
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 = {});
// @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<IsEmptyObject<{}>>(true);
expectType<IsEmptyObject<typeof foo>>(true);
Expand All @@ -23,7 +29,8 @@ expectType<IsEmptyObject<() => 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);
4 changes: 2 additions & 2 deletions test-d/exact.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {expectError} from 'tsd';
import type {Exact, Opaque} from '../index';

{ // Spec - string type
Expand Down Expand Up @@ -398,7 +397,8 @@ import type {Exact, Opaque} from '../index';
const function_ = <T extends Exact<{a: TaggedNumber}, T>>(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
Expand Down
10 changes: 5 additions & 5 deletions test-d/except.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 = {
Expand Down
5 changes: 3 additions & 2 deletions test-d/if-any.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expectError, expectType} from 'tsd';
import {expectType} from 'tsd';
import type {IfAny} from '../index';

declare const _any: any;
Expand All @@ -10,4 +10,5 @@ expectType<IfAny<any, 'T', 'F'>>('T');
expectType<IfAny<string, 'T', 'F'>>('F');

// Missing generic parameter
expectError<IfAny>(_any);
// @ts-expect-error
type A = IfAny;
7 changes: 3 additions & 4 deletions test-d/if-never.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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<IfNever<never>>(true);
expectType<IfNever<string>>(false);
expectType<IfNever<never, 'T', 'F'>>('T');
expectType<IfNever<string, 'T', 'F'>>('F');

// Missing generic parameter
expectError<IfNever>(_never);
// @ts-expect-error
type A = IfNever;
7 changes: 3 additions & 4 deletions test-d/if-unknown.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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<IfUnknown<unknown>>(true);
expectType<IfUnknown<string>>(false);
expectType<IfUnknown<unknown, 'T', 'F'>>('T');
expectType<IfUnknown<string, 'T', 'F'>>('F');

// Missing generic parameter
expectError<IfUnknown>(_unknown);
// @ts-expect-error
type A = IfUnknown;
16 changes: 9 additions & 7 deletions test-d/includes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expectError, expectType} from 'tsd';
import {expectType} from 'tsd';
import type {Includes} from '../index';

const includesEmptyArray: Includes<[], 'abc'> = false;
Expand Down Expand Up @@ -38,18 +38,20 @@ expectType<false>(nullIncludesUndefined);
const nullIncludesNullPass: Includes<[null], null> = true;
expectType<true>(nullIncludesNullPass);

declare const anything: any;

// Verify that incorrect usage of `Includes` produces an error.

// Missing all generic parameters.
expectError<Includes>(anything);
// @ts-expect-error
type A0 = Includes;

// Missing `Item` generic parameter.
expectError<Includes<['my', 'array', 'has', 'stuff']>>(anything);
// @ts-expect-error
type A1 = Includes<['my', 'array', 'has', 'stuff']>;

// Value generic parameter is a string not an array.
expectError<Includes<'why a string?', 5>>(anything);
// @ts-expect-error
type A2 = Includes<'why a string?', 5>;

// Value generic parameter is an object not an array.
expectError<Includes<{key: 'value'}, 7>>(anything);
// @ts-expect-error
type A3 = Includes<{key: 'value'}, 7>;
2 changes: 1 addition & 1 deletion test-d/int-range.ts
Original file line number Diff line number Diff line change
@@ -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>;
Expand Down
2 changes: 1 addition & 1 deletion test-d/internal/require-none.ts
Original file line number Diff line number Diff line change
@@ -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'>;
Expand Down
5 changes: 3 additions & 2 deletions test-d/is-any.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expectError, expectType} from 'tsd';
import {expectType} from 'tsd';
import type {IsAny} from '../index';

declare const anything: any;
Expand All @@ -16,4 +16,5 @@ expectType<IsAny<undefined>>(false);
expectType<IsAny<void>>(false);

// Missing generic parameter
expectError<IsAny>(anything);
// @ts-expect-error
type A = IsAny;
10 changes: 5 additions & 5 deletions test-d/is-equal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expectError, expectType} from 'tsd';
import {expectType} from 'tsd';
import type {IsEqual} from '../index';

const notEqualNumberAndString: IsEqual<number, string> = false;
Expand All @@ -19,10 +19,10 @@ expectType<false>(notEqualAnyAndNever);
const notEqualArrayOfAnyAndArrayOfNever: IsEqual<[any], [never]> = false;
expectType<false>(notEqualArrayOfAnyAndArrayOfNever);

declare const anything: any;

// Missing all generic parameters.
expectError<IsEqual>(anything);
// @ts-expect-error
type A = IsEqual;

// Missing `Y` generic parameter.
expectError<IsEqual<number>>(anything);
// @ts-expect-error
type B = IsEqual<number>;
19 changes: 11 additions & 8 deletions test-d/is-literal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expectError, expectType} from 'tsd';
import {expectType} from 'tsd';
import type {
IsLiteral,
IsStringLiteral,
Expand Down Expand Up @@ -54,11 +54,14 @@ expectType<IsBooleanLiteral<typeof _boolean>>(false);
expectType<IsSymbolLiteral<typeof symbolLiteral>>(true);
expectType<IsSymbolLiteral<typeof _symbol>>(false);

declare const anything: any;

// Missing generic parameter
expectError<IsLiteral>(anything);
expectError<IsStringLiteral>(anything);
expectError<IsNumericLiteral>(anything);
expectError<IsBooleanLiteral>(anything);
expectError<IsSymbolLiteral>(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;
5 changes: 3 additions & 2 deletions test-d/is-never.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expectError, expectType} from 'tsd';
import {expectType} from 'tsd';
import type {IsNever} from '../index';

declare const _never: never;
Expand All @@ -16,4 +16,5 @@ expectType<IsNever<undefined>>(false);
expectType<IsNever<void>>(false);

// Missing generic parameter
expectError<IsNever>(_never);
// @ts-expect-error
type A = IsNever;

0 comments on commit dfa0611

Please sign in to comment.