Proposal static type constraints features

YU HengChun achun.shx at
Mon Jun 4 03:32:22 UTC 2018

> A separate question is, how would String cover strings across realms, considering that 'abc' instanceof String already returns false even in the same realm?

There is no such way in the proposal.


The real purpose of the expression in void is not the operation.
It is description for typing, the literal semantics.
It is compatible with the old engine. Even if it is operated, it will not have side effects.

The new engine will extract the type description, and will not operate on it.

void 中的表达式不是用来计算的, 是为了描述类型, 只是为了兼容陈旧的引擎, 在陈旧的引擎中它也是合法的, 老引擎里面它会被计算, 但不会有副作用.

新引擎会提取其中的类型描述, 不会去运算它.

So, The correct way is:

function CustomString(x = void( Object instanceof String) || 'abc' ) {
  // ...

The form `Object instanceof TYPE` is for backward compatibility.

More information about the es-discuss mailing list