Proposal to add symbol: "hasInstanceStrict"

Mike Samuel mikesamuel at gmail.com
Sun Feb 18 17:43:16 UTC 2018


Must hasInstanceStrict's parameter remain untyped for a guard to complete
or is there a top type with an unguarded hasInstanceStrict that these
checks bottom out on?

"has" to my ear sounds like it should return a boolean.  Maybe "require."



On Feb 18, 2018 11:30 AM, "Aleksander Efremov" <mr.efrem at gmail.com> wrote:

It’s attempt to provide intermediate layer for implementation of runtime
type checking.

```
class PrimitiveNumber {
        static [Symbol.hasInstanceStrict](x) {
                if (typeof x !== ’number’) {
                        throw new TypeError(‘Invalid type’);
                }
        }
}

function sum(a: PrimitiveNumber, b: PrimitiveNumber) {
        return a + b;
}

const c: PrimitiveNumber = sum(1, 2);
```

I.e. when appears assignment of variable (const) if then follows `:
<class>` then JS runtime must to call method `static
[Symbol.hasInstanceStrict](x)` and transfer to there assignable value.

_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180218/5f07afb4/attachment.html>


More information about the es-discuss mailing list