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.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"
> 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.)
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.