News for hackers. Stuff that matters.
Re:Towards Scala 3 by munificent on Friday April 20, 2018 @01:49PM (#16886894)
> Is it actually unsound if you perform no casting?

Yeah, it is. At the very least, I know that function parameters are bivariant, which isn't sound:

    function foo(callback: (obj: Object) => void) {
      callback("not a bool");
    }

    function main() {
      foo(function (bool: Boolean) {
        if (bool) window.console.log("!");
      });
    }
This compiles without a type error but ends up assigning a string to a parameter of type bool.
Re:Towards Scala 3 by ItsMe000001 on Friday April 20, 2018 @02:01PM (#16887011)
I'm a Flow user rather than TS (and Flow complains about that code out of the box), but you are not telling us all:

Since TS 2.6, if you enable all the optional "strict" mode checks than TypeScript does complain about that code.

I see no disadvantage in those checks, e.g. "strictFunctionTypes", being optional, since you can always make them mandatory for your own project(s).

To test it:

- Go to the TS Playground at https://www.typescriptlang.org/play/

- Enter the above code

- Select "Options" and enable at least "strictFunctionTypes"

Re:Towards Scala 3 by naasking on Friday April 20, 2018 @02:07PM (#16887063)
Is that option documented somewhere? I imagine there are some tradeoffs with enabling it.
Re:Towards Scala 3 by ItsMe000001 on Friday April 20, 2018 @02:14PM (#16887139)
https://www.typescriptlang.org/docs/handbook/release-notes/t...

> TypeScript 2.6 introduces a new strict checking flag, --strictFunctionTypes.

> The --strictFunctionTypes switch is part of the --strict family of switches, meaning that it defaults to on in --strict mode.

> Under --strictFunctionTypes function type parameter positions are checked contravariantly instead of bivariantly.

> ...(etc.)

Re:Towards Scala 3 by naasking on Friday April 20, 2018 @02:28PM (#16887288)
Contravariance then, right. Thanks! I haven't gotten into Typescript yet, and at this point it looks fairly large and a little daunting, so this is helpful.
Re:Towards Scala 3 by tomerbd on Saturday April 21, 2018 @02:01AM (#16890186)
And this project is super interesting: https://1c.wizawu.com/#/whatis Use TypeScript on JVM with both NPM and Maven dependencies
Re:Towards Scala 3 by coryfklein on Friday April 20, 2018 @05:08PM (#16888446)
The major tradeoff, IMO, is that it is even toggle-able at all, let alone being a feature switch that is enabled by default.

If you enter any random TS project today, odds are it isn't using that switch, and enabling the switch will lead you down a month long rabbit-hole of fixing cascading type errors.

Re:Towards Scala 3 by bjterry on Friday April 20, 2018 @10:23PM (#16889672)
Not only that, but since it isn't required many libraries in the ecosystem won't be using it. Comparing my experiences with TypeScript and Flow vs. my experiences with Haskell, any optional type system is going to leave a lot of gaps if you don't have a pretty strict not-invented-here culture.
Re:Towards Scala 3 by ihsw2 on Friday April 20, 2018 @02:23PM (#16887224)
Tradeoffs? It might frustrate some people more accustomed to JS' loose type system.