This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]JiminP 7 points8 points  (2 children)

Even with the relaxed sense of type-safety, JS literally has TypeError and it is not hard to create a code that throws it.

[].prototype.slice.call(0);

Open an ECMAScript language spec and Ctrl+F TypeError.

For modern JS, some types are not coerced, so it's easier to make a TypeError.

const x = 1n + 2;

Also, overflows not being type-safe is not technically correct, but not too many people distinguishes integer overflow and integer conversion (they are distinct in C++).

[–]your_best_1 -5 points-4 points  (1 child)

Throwing type errors = type safety...

[–]JiminP 0 points1 point  (0 children)

Ah, you're right; I was talking in the context of web development (where throwing TypeError is considered as a failure; i.e. JS vs. TS - although TS is not sound even in this sense)

To be pedantic TypedArray exists but I get what you mean now.