คำถามในหัวข้อ 'typeguards'

typescript อนุมานว่าฟิลด์นั้นเป็นความจริง (ไม่สามารถไม่ได้กำหนด) โดยไม่มีตัวป้องกันประเภทที่ผู้ใช้กำหนด
type Item = { left?: { photoSrc: string }; }; type ItemRequired = { left: { photoSrc: string }; }; const item: Item = {} as any; if (item.left) { const itemRequired: ItemRequired = item; // fails. Typescript still says left may be...
205 มุมมอง