Proposal: Optional Static Typing (Part 3)

Michał Wadas michalwadas at gmail.com
Sun Jan 14 02:50:33 UTC 2018


I have many concerns about typing.

*Types are opinionated*

Choice of type system significantly affects code that people write. As
observed in many codebases, adoption of TypeScript favors object oriented
style over functional style.

Choosing type system descending from Java type system is message "creators
of language endorse OOP as main JavaScript paradigm". It's fine for
TypeScript to take opinionated approach, but it's unlikely with TC39.

If you don't see limitations of eg. TypeScript type system, try to express
in its terms: "function takes subclass of Foo as parameter Ctor and returns
subclass of Ctor extended by some methods". Not to mention reflection here
(think of Bluebird's promisification)...

Functional languages usually provide better type systems, but complexity
can be prohibitive. Moreover, I don't know any programming language that
combines type system as strong as eg. Idris and object oriented
programming.

*Runtime type checking*

Runtime type checking would incur significant cost on browsers (and
JavaScript parse time is already an issue for smartphone CPUs). It's
especially important to remember about dynamic nature of JavaScript.
TypeScript can rely on assumption that no one creates accessors on
Object.prototype or Array prototype, but it's unacceptable for language
feature.

Therefore, chance of someone calling Object.defineProperty(Array.prototype,
7,...) requires type checking on every property assignment. There hundreds
of ways to screw type system, including changes in inheritance in runtime.

foo instanceof Foo; // true
foo instanceof Foo; // false
foo instanceof Foo; // true

Ups, someone overwritten Function.prototype[Symbol.hasInstance] with () =>
Math.random() > 0.5.

*Compilation time type checking*

Compilation time type checking requires tooling. If language relies on
external  tool to strip type definitions, why whole typing can't be left to
external tool? External tools can iterate faster than language and can
compete.

*People hates writing types*

That's why C++ have auto, Kotlin have val, and it's  significant reason why
dynamically typed languages became popular. *Type inference* is awesome,
but integrating it with existing JavaScript code in backwards compatible
way seems to be hard.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180114/fca2a18e/attachment.html>


More information about the es-discuss mailing list