-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change inference behaviour in old TS versions
- Loading branch information
Showing
3 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// taken from https://github.com/joonhocho/tsdef | ||
// return True if T is `any`, otherwise return False | ||
export type IsAny<T, True, False = never> = ( | ||
| True | ||
| False) extends (T extends never ? True : False) | ||
? True | ||
: False | ||
|
||
// taken from https://github.com/joonhocho/tsdef | ||
// return True if T is `unknown`, otherwise return False | ||
export type IsUnknown<T, True, False = never> = unknown extends T | ||
? IsAny<T, False, True> | ||
: False | ||
|
||
export type IsEmptyObj<T, True, False = never> = T extends any | ||
? {} extends T | ||
? IsUnknown<T, False, IsAny<T, False, True>> | ||
: False | ||
: never | ||
|
||
/** | ||
* returns True if TS version is above 3.5, False if below. | ||
* uses feature detection to detect TS version >= 3.5 | ||
* * versions below 3.5 will return `{}` for unresolvable interference | ||
* * versions above will return `unknown` | ||
* */ | ||
export type AtLeastTS35<True, False> = IsUnknown< | ||
ReturnType<<T>() => T>, | ||
True, | ||
False | ||
> | ||
|
||
export type IsUnknownOrNonInferrable<T, True, False> = AtLeastTS35< | ||
IsUnknown<T, True, False>, | ||
IsEmptyObj<T, True, False> | ||
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters