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

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.



Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: