Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tsd (and pin TypeScript to current minor) #839

Merged
merged 13 commits into from
Apr 2, 2024
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"devDependencies": {
"expect-type": "^0.15.0",
"npm-run-all2": "^6.1.2",
"tsd": "^0.29.0",
"tsd": "^0.31.0",
"typescript": "~5.4.3",
"xo": "^0.58.0"
},
Expand Down
8 changes: 5 additions & 3 deletions source/internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,11 @@ Multiple call signatures cannot currently be supported due to a TypeScript limit
@see https://github.com/microsoft/TypeScript/issues/29732
*/
export type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> =
T extends {(...arguments_: infer A): unknown; (...arguments_: any[]): unknown}
? unknown[] extends A
? false
T extends {(...arguments_: infer A): unknown; (...arguments_: infer B): unknown}
? B extends A
? A extends B
? false
: true
: true
: false;

Expand Down
22 changes: 22 additions & 0 deletions test-d/internal/has-multiple-call-signatures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {expectType} from 'tsd';
import type {HasMultipleCallSignatures} from '../../source/internal';

type Overloaded = {
(foo: number): string;
(foo: string, bar: number): number;
};

type Overloaded2 = {
(foo: number | undefined): string;
// eslint-disable-next-line @typescript-eslint/unified-signatures
(foo: number): string;
};

type Namespace = {
(foo: number): string;
baz: boolean[];
};

expectType<true>({} as HasMultipleCallSignatures<Overloaded>);
expectType<true>({} as HasMultipleCallSignatures<Overloaded2>);
expectType<false>({} as HasMultipleCallSignatures<Namespace>);
15 changes: 15 additions & 0 deletions test-d/readonly-deep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,18 @@ type VoidTypeExpected = {
};
declare const voidType: ReadonlyDeep<VoidType>;
expectType<VoidTypeExpected>(voidType);

// Standalone tests

// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const readonlyNamespace = {} as ReadonlyDeep<{
(foo: number): string;
baz: boolean[];
}>;
expectType<((foo: number) => string) & {
readonly baz: readonly boolean[];
}>(readonlyNamespace);
expectAssignable<{
(foo: number): string;
readonly baz: readonly boolean[];
}>(readonlyNamespace);
15 changes: 15 additions & 0 deletions test-d/writable-deep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,18 @@ const fullyWritableData = {
},
};
expectAssignable<WritableDeep<ReadonlyDeep<typeof fullyWritableData>>>(fullyWritableData);

// Standalone tests

// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const writableNamespace = {} as WritableDeep<{
(foo: number): string;
readonly baz: readonly boolean[];
}>;
expectType<((foo: number) => string) & {
baz: boolean[];
}>(writableNamespace);
expectAssignable<{
(foo: number): string;
baz: boolean[];
}>(writableNamespace);
6 changes: 1 addition & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,5 @@
// "noUncheckedIndexedAccess": true, // TODO: Enable.
"noPropertyAccessFromIndexSignature": true,
"useDefineForClassFields": true,
},
"exclude": [
// Ignore `WriteableDeep` error temporarily, remove when #833 are fixed.
"test-d/writable-deep.ts",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be able to add a test to test-d/writable-deep.ts too? So it doesn't regress again in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sindresorhus Sure, there is a test already, but most tests in both of these are indirect ones which gives some cascading one, I'll add en explicit one 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sindresorhus Done ✔️

]
}
}