ทริกที่ควรรู้ตอนเรียน TypeScript
(cstrnt.dev)- Readonly
→ Array และ Object ของ JS เป็นแบบอ้างอิง จึงสามารถแก้ไขได้ ช่วยลด side effect
- Any vs Unknown
→ ตอนคอมไพล์สามารถบังคับตรวจสอบ type ที่ไม่ทราบได้ จึงควรใช้ Unknown แทน any
- การทำ Typing ให้ object ด้วย Record
→ ใช้ Record แทน interface
1 ความคิดเห็น
เพิ่มเติมจากคอมเมนต์ใน HN https://news.ycombinator.com/item?id=28837181
→ https://www.typescriptlang.org/docs/handbook/utility-types.html
→ ภาษาเกาหลี https://typescript-kr.github.io/pages/utility-types.html
ในฟังก์ชัน ให้คืนค่าเป็น Sometype|null แทน Sometype|undefined
Indexed Access Types https://typescriptlang.org/docs/handbook/…