Hacker News new | ask | show | jobs
by uk_programmer 2295 days ago
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.