Skip to content

Commit

Permalink
IsAny: Fix circular constraint error on TypeScript 5.4+ (#993)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarpoole authored Dec 2, 2024
1 parent ca449dc commit 32d94dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion source/is-any.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Can eventually be replaced with the built-in once this library supports
// TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
type NoInfer<T> = T extends infer U ? U : never;

/**
Returns a boolean for whether the given type is `any`.
Expand Down Expand Up @@ -26,4 +30,4 @@ const anyA = get(anyObject, 'a');
@category Type Guard
@category Utilities
*/
export type IsAny<T> = 0 extends 1 & T ? true : false;
export type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
7 changes: 7 additions & 0 deletions test-d/is-any.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ expectType<IsAny<void>>(false);
// Missing generic parameter
// @ts-expect-error
type A = IsAny;

// Verify that are no circular reference issues
// https://github.com/sindresorhus/type-fest/issues/846
type OnlyAny<T extends IsAny<T> extends true ? any : never> = T;
type B = OnlyAny<any>;
// @ts-expect-error
type C = OnlyAny<string>;

0 comments on commit 32d94dd

Please sign in to comment.