[251124] TIL
Today I Learned (2025-11-24)
μ€λ κ°λ° ν κ²
- νλ ¨μ ν΅κ³ API μ°λν¨
- νλ ¨μ μμΈλ³΄κΈ° νμ΄μ§ API μ°λν¨
- νλ ¨μ μ€ν€λ§ discriminatedUnion νμ
μ μ©ν¨
- κΈ°κ΄ μΆκ° ExistInfo μ΄κΈ°ν μμ ν¨
- λ‘κ·ΈμΈ μ μ μ μνμ κΈ°κ΄ID μ£Όμ
μμ ν¨
- boolean falseμΈ κ²½μ° query param μ μ©λλλ‘ μμ ν¨
- νμ/κΈ°κ΄ μμ κ³ κ° μμνν¨
- ν
μ΄λΈ κΈ°λ³Έκ° truncate = true μ€μ ν¨
- μ€νμΌ μμ , λ μ΄μμ μμ , 문ꡬ λ³κ²½, λ€μ΄λ° λ³κ²½ν¨
κ°λ°νλ©΄μ λλ κ²
- type predicate μ΄λ€ κ°μ΄ νΉμ νμ
μΈμ§ νμΈν΄μ£Όλ ν¨μμ λ°ν νμ
νκΈ°
- predicate : μ΄λ€ μ¬μ€μ΄ μ°ΈμΈμ§ κ±°μ§μΈμ§ λ§ν΄μ£Όλ κ², μ£Όμ΄μ λν΄ μ€λͺ
ν΄μ£Όλκ²
type Animal =
| { type: "cat"; meow: () => void }
| { type: "dog"; bark: () => void };
function isCat(animal: Animal): animal is { type: "cat"; meow: () => void } {
return animal.type === "cat";
}
const pet: Animal = { type: "dog", bark: () => {} };
if (isCat(pet)) {
pet.meow(); // ok!
} else {
pet.bark(); // ok!
}
Leave a comment