๋๋ํ๋ฅผ ์ง์ฐ๊ณ ๋์ค๋ ์๋ฌ : 'ui'์(๋) ์ด๋์ ๋ผ์ด์ ๊ฐ ์๊ณ ์์ฑ์์ ํ ๋น๋์ด ์์ง ์์ต๋๋ค.ts(2564)
ํ์ ์คํฌ๋ฆฝํธ๊ฐ ํน์ null์ผ์ง๋ ๋ชจ๋ฅด๋ ๋์์ ์ปดํ์ผ์๋ฌ๋ผ์ธ ๋์์ฃผ๋๋ฐ
ํ๋ก๊ทธ๋๋จธ๊ฐ null์ด ์๋๋ผ๊ณ ํ์ ์ด ์์๋์
TSC Null์ฒดํฌ์ ์์ธ ์ฒ๋ฆฌ ํด์ฃผ๋ ๊ฒ
Non-null assertion operator
A new ! post-fix expression operator may be used to assert that its operand is non-null and non-undefined in contexts where the type checker is unable to conclude that fact. Specifically, the operation x! produces a value of the type of x with null and undefined excluded. Similar to type assertions of the forms <T>x and x as T, the ! non-null assertion operator is simply removed in the emitted JavaScript code.
null์ด ์๋ ์ด์ค์ ์ฐ์ฐ์
์๋ก์ด !ํ์ ํํ์ ์ฐ์ฐ์๋ ์ ํ ๊ฒ์ฌ๊ธฐ๊ฐ ํด๋น ์ฌ์ค์ ๊ฒฐ๋ก ์ง์ ์ ์๋ ์ปจํ ์คํธ์์ ํผ์ฐ์ฐ์๊ฐ null์ด ์๋๊ณ ์ ์๋์ง ์์์ ์ฃผ์ฅํ๋ ๋ฐ ์ฌ์ฉํ ์ ์์ต๋๋ค. ํนํ ์ด ์์ ์ with ๋ฐ ์ ์ธ x!์ ํ์ ๊ฐ์ ์์ฑํฉ๋๋ค . ํ์ ๋ฐ ์ ํ์ ์ด์ค์ ๊ณผ ์ ์ฌํ๊ฒ null ์ด ์๋ ์ด์ค์ ์ฐ์ฐ์๋ ๋ด๋ณด๋ด์ง JavaScript ์ฝ๋์์ ๊ฐ๋จํ ์ ๊ฑฐ๋ฉ๋๋ค.xnullundefined<T>xx as T!
'TypeScript > ํ์ ์คํฌ๋ฆฝํธ TypeScript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ์ ์คํฌ๋ฆฝํธ] ์ ์ฉํ ์ต์คํ ์ , Auto import (0) | 2022.05.05 |
---|---|
[ํ์ ์คํฌ๋ฆฝํธ] .d.ts ์ ๋ํ ์ดํด (0) | 2022.05.04 |
ํ์ ์คํฌ๋ฆฝํธ + ๋ฆฌ๋์ค (0) | 2022.05.01 |
[ํ์ ์คํฌ๋ฆฝํธ] ํฉํ ๋ฆฌ ํจํด (0) | 2022.04.28 |
[ํ์ ์คํฌ๋ฆฝํธ] ์ฐ์ต์ฉ์ผ๋ก ์์ฃผ ์ฌ์ฉํ๋ ์ธํ (0) | 2022.04.27 |