#Why is any assignable to string
1 messages · Page 1 of 1 (latest)
pretty sure any "extends" everything and everything "extends" any
any any value can be assigned to string, any string value can be assigned to any
that's kinda the point of any
maybe you're thinking of unknown
Doesnt any contain all values though? So for example numbers wouldnt be assignable to string
or is any just an escape hatch? 🤔
any doesn't "contain" anything, it disables typechecking
it isn't typesafe
unknown is the typesafe, uh equivalent i guess
ah ok, so my understanding that it is a top type was incorrect. Thanks a lot @knotty shale 🙏
any is the side type
lol
type T = any extends string ? 1 : 0;
// ^? - type T = 0 | 1
any is wild
eh i guess that makes sense with the original, since true | never = true
right
any is the quantum type - its sometimes the top type and other times the bottom type
whichever is more permissive
so it's a switch
type A = string | number | symbol /* 1:6 */``````ts
type B = never /* 2:6 */``````ts
type C = string | number | symbol /* 3:6 */```
its funny, it just swaps places between unknown and never in different contexts
so in this context its the same as never
in others its more like unknown
so like as a function argument, with contravariance, that would be emulating never?
mm that is definitely not the right word
another is with assignment, if its on the left hand side its like unknown, but if its on the right hand side its like never
as never is basically the same thing as as any
const a: string = 1 as never
!ts
const a: string = 1 as never
its probably not formally implemented like this
but the observed behaviour is consistent with it
given that any predates both unknown and never
!resolved