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

TypeScript does support writing "quacksLike" functions. The feature is "type guards" and it lets you write a boolean function to test the type of an argument, and TS's flow control code understands it at compile time.

    const something: Animal = ...

    if (isDuck(something)) {
        someThing.quack();  // TS can OK this
    }


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

Search: