TypeScript strictNullChecksについて

strictNullChecksがfalseの場合、すべての型にnullもしくはundefinedを入れることができます。
type Hoge = string
const str1: Hoge = null //エラーにならない
const str2: Hoge = undefined //エラーにならないstrictNullChecksをtrueにすると、明示的にnullやundefinedを型に指定しない限りエラーになります。
type Hoge = string
const str1: Hoge = null //エラーにならない
const str2: Hoge = undefined //エラーにならないTypeScript Playground はデフォルトでtrueなのでご注意ください。






最近のコメント