LoginSignup
0
0

【TypeScript】非nullアサーション演算子について

Posted at

非nullアサーション演算子(!)を使用するとnullまたはundefinedでないことをTypeScriptに伝えることができます。

let sample: string | null = fetchSomeNullableString()
let test: string = sample! // 非nullアサーション演算子を使用

上記の例では、sampleの型はstring | nullですが、非nullアサーション演算子を使用することで、string型であるtestsampleを代入できています。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0