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

Yes. However you can for example do the following in typescript:

    function someFunction(obj?:DuckType) {
        //Snip other logic
        someOtherFunction(obj);
    }

    function someOtherFunction(obj:DuckType) {

    }
The type checker catch that. So you still have to do:

    function someFunction(obj?:DuckType) {
        obj = obj || { /* set some object properties */
        //Snip other logic
        someOtherFunction(obj);
    }

    function someOtherFunction(obj:DuckType) {

    }
I have found plenty of examples where people haven't set a default value because the compiler hasn't flagged anything wrong with the code and you get an uncaught reference error.



Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: