Why does "any" type disable typechecking prematurely?

25 views Asked by At

Why does using the any type disable strict null checks in the below code? Is this a bug?

type SomeType = any;

interface Optional {
  some?: { 
    key: SomeType;
  };
}

interface NotOptional {
  key: SomeType;
}

const opt: Optional = {};

const val: NotOptional = {
  key: opt.some?.key // no error if SomeType is any
}

Playground

1

There are 1 answers

0
Poltix On

It works as expected since that's how any is meant to work.