Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Perhaps explicitly setting the types might do it?

    const x: number[]= [1,2]
    const y: number | undefined = x[666]
    const z: number = y + 3
EDIT: Just tried, still works


It works because `undefined + number -> NaN`, and NaN is a number.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: