Hacker News new | past | comments | ask | show | jobs | submit login

You can also use 'type assertions' to minimise restructuring, eg, the following is the same number of lines as your first example (and compiles to identical code):

    const a = A()
    a.b = new SubtypeOfB()
    (<SubtypeOfB> a.b).attributeOfSubtypeOfB = 123 //works



Isn't this dangerous?


No, you're just telling TypeScript you know what Type it is and it will let you treat it as that Type.




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

Search: