Type Guards and Differnetiating Types
Last updated
Was this helpful?
Last updated
Was this helpful?
A type guard is some expression that performs a runtime check that guarantees the type in some scope. νμ μ΄ λ¬Έμμ¬λ μ«μλ₯Ό μ¨λ λλ 보μ₯μ ν΄μ€λ€.(?)
four main ways to use type guards
in
keyword
typeof
keyword
instanceof
keyword
predicate
parameterName
μ νμ¬ ν¨μ μκ·Έλμ²μ λ§€κ° λ³μ μ΄λ¦μ΄μ΄μΌ νλ€.
μ΄ κ°λ μ or(|)μΌλ λ§μ΄ μ°μ΄λλ° μ΄ orμ΄ λ³΅μ‘νλ€. μ΄λ΄λ νμ μ μ€μ ν΄ μ€ μ μλκ² νμ κ°λμ΄λ€.