Closed
Description
There is a category of bugs caused by unintended coercion at runtime. Such bugs can be found by the compiler. Having an option that bans such coercion would be a great addition.
examples of the problem:
// before (typechecks)
let isFirst: boolean;
// ... later in code
if (!isFirst) {
// do stuff
}
// after refactoring (still typechecks)
let isFirst: () => boolean;
// ... later in code
if (!isFirst) {
// got a bug, unreachable code
}
// before (typechecks)
let counter: number;
let kind: string;
// ... later in code
let id = '--' + kind + (counter++); // works: --blah-blah-341279
// after refactoring (still typechecks)
let counter: number;
let kind: {
type: string;
sort: string;
};
// ... later in code
let id = '--' + kind + (counter++); // now a bug: --[object Object]-341279