I believe it’s largely because of these defaults that the idea that TypeScript isn’t really checking types persists. Without the any type, or loose undefined and null checks, your types are as validated as they can be. The only failure point is deserialization or an import which doesn’t type check. And deserialization has this problem in every language.
When you compile C to machine code the executed binary isn’t checking types. This is no different from Typescript that’s been compiled to JavaScript.
function mutateArray(
arr: (string | number)[]
) {
arr.push(1);
}
const a: string[] = ["one", "two"];
mutateArray(a);
a is now a string[] with a number insideIs there a name for this failure mode?
I came across it on ThePrimeagen's YouTube channel: https://youtu.be/u1WmiqlrqL0
That's not the reason.
TypeScript's main design goal was to enable developers to gradually introduce types in codebases that spent years being written purely in JS.
There's still demand for this feature and those who start off with TypeScript set their own config anyway.
I've dealt with people using all kinds of escape hatches, but 2/3 of the time it's caused by lack of proficiency in the language.
The rest is either someone being in a hurry or just not serious about their job.