type IsAny<T> = [0, T] extends [T, 1] ? true : false
Solution by 2083335157 #35017
// anyๆฏไธ็ปๅ
ๅซๆๆ็ฑปๅ็็ฑปๅใๅ ๆญค๏ผๅฆๆไฝ ๅฐ็ฑปๅ1ๆทปๅ ๅฐany็ฑปๅไธญ๏ผๅฎไป็ถๆฏany็ฑปๅใ
// ไฝ ๅฏไปฅๅฐไปปไฝไบ็ฉ่งไธบๆฐๅญฆไธ็ๆ ็ฉทๅคงใๆ ็ฉทๅคง+1ไป็ถๆฏๆ ็ฉทๅคงใ
type IsAny<T> = 0 extends (1 & T) ? true : false
Solution by ouzexi #34221
type IsNotAny<T> = T extends never ? true : never
type IsAny<T> = [IsNotAny<T>] extends [never] ? false : true
Solution by PiligrimStas #33788
// your answers
type IsAny<T> = [T, 1] extends [0, T] ? true : false
Solution by DevilTea #33440
// your answers
type IsAny<T> = (T extends never ? true : false) extends true ?
false
:(T extends never ? true : false) extends false ?
false
:true;
It seems right ,but i don't know why.
Solution by sciencefunq #32967
type IsAny<T> = (<G>() => G extends T ? 1 : 2) extends (<G>() => G extends any ? 1 : 2) ? true : false;
Solution by rldnd #32908
type IsAny<T> = keyof any extends keyof T
? 1 extends T
? true
: false
: false
keyof any
and keyof never
are equal. (symbol | number | string)any
can be assigned, never
cannot.Solution by findmio #32806
// your answers
type Equality<X, Y> = (<T>() => T extends X ? 1 : 2) extends <P>() => P extends Y ? 1 : 2 ? true : false
type IsAny<T> = Equality<T, any> extends true ? true : false;
Solution by kakasoo #32689
type IsAny<T> = 1 extends "jarvey" & T ? true : false;
Solution by DoubleWoodLin #28936
type IsAny<T> = 0 extends (1 & T) ? true : false;
Solution by jjswifty #27543
type IsAny<T> = 0 extends (1 & T) ? true : false
Solution by smileboyi #27497
// your answers
type IsAny<T> = (any extends T & 0 ? 1 : 2) extends 1 ? true : false
Solution by studymachiney #25129
type IsAny<T> = 2 extends 1 & T ? true : false;
// type IsAny<T> = Equal<T, any>;
// old way
// type IsAny<T> = (any extends T & 0 ? 1 : 2) extends 1 ? true : false; //any็นๆง้ข
Solution by E-uler #24702
// your answers
type IsAny<T> = 0 extends 1&T ?true:false
Solution by walker-hzx #24543
type IsAny<T> = Equal<T, any> extends true ? true : false
Solution by NeylonR #24444
Only any
is both a subtype and a supertype of nearly everything. I'm using never
here but it works with almost any type you can come up with.
type IsNever<T> = T extends never ? true : false;
type IsAny<T> = boolean extends IsNever<T> ? true : false;
Solution by Robinsstudio #23650
// your answers
type IsAny<T> = Equal<T, any> extends true ? true : false
Solution by snakeUni #23511
// your answers
type IsAny<T> = 'hello' extends T & 'world' ? true : false;
Solution by jxhhdx #22854
// your answers
type IsAny<T> = boolean extends (T extends 1
? T extends 2
? true
: false
: false
)
? true : false
Solution by 437204933 #22293
type IsAny<T> = 'A' extends T & 'B' ? true : false
Solution by drylint #22216
type IsAny<T> = 1 | 2 extends (T extends never ? 1 : 2) ? true : false
Solution by goddnsgit #21881
type IsAny<T> = Equal<T, any>;
Solution by ivbrajkovic #21638
type IsAny<T> = "ๅปๅป" extends T ? true : false;
Solution by so11y #21112
// your answers
type IsAny<T> = 0 extends 1 & T ? true : false
Solution by YqxLzx #20667
// your answers
type IsAny<T> = any[] | object | string | number | undefined | never extends T ? [T] extends [object | string | number | undefined | never] ? true : false : false
Solution by YqxLzx #20581
type IsAny<T> = 0 extends (1 & T) ? true : false;
originated from https://github.com/type-challenges/type-challenges/issues/232
Solution by zhaoyao91 #20489
// your answers
type IsAny<T> = "any" extends 1 & T ? true : false;
type IsAny2<T> = (<A>() => A extends T ? 1 : 0) extends <A>() => A extends any
? 1
: 0
? true
: false;
Solution by fengjinlong #20211
type EqualTo<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
type IsAny<T> = EqualTo<T, any>;
Solution by CaoXueLiang #19028
type IsAny<T> = 'any' extends 1 & T ? true : false
type IsAny<T> = (<A>() => A extends T ? 1 : 0) extends (<A>() => A extends any ? 1 : 0) ? true : false
type a = 1 & any // any
Solution by milletlovemouse #18709
// your answers
type IsAny<T> = (<S>(S: S) => S extends T ? 1 : 2) extends (<R>(R: R) => R extends any ? 1 : 2) ? true : false;
Solution by jiaaoMario #17220