News for hackers. Stuff that matters.
Re:Fast and precise type checking for JavaScript by curryhoward on Thursday November 09, 2017 @12:03AM (#15660015)
Just as an example, this program type checks in TypeScript but crashes at runtime:

    class Dog {
    }

    class Greyhound extends Dog {
        doGreyhoundThing(): void {
            console.log("I am a greyhound!");
        }
    }

    class Poodle extends Dog {
        doPoodleThing(): void {
            console.log("I am a poodle!");
        }
    }

    function f(g:(Dog) => void) : void {
        let hound: Greyhound = new Greyhound();
        g(hound);
    }

    function h(p: Poodle): void {
        p.doPoodleThing();
    }

    f(h);
`f(h);` would be a type error if function types were contravariant in their argument types. TypeScript made the unsound choice to let function types be bivariant in their argument types, which the authors claim is justified for practical reasons. More info here: https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-fun...
Re:Fast and precise type checking for JavaScript by besquared on Thursday November 09, 2017 @12:28AM (#15660114)
They added contravariant functions in 2.6 using the compiler flag --strictFunctionTypes as described in this PR https://github.com/Microsoft/TypeScript/pull/18654
Re:Fast and precise type checking for JavaScript by reacweb on Thursday November 09, 2017 @05:24AM (#15661287)
When I was student (1992), a friend noticed exactly the same issue in the eiffel language. They answered also that the incorrect check was more practical.