Proposal to add symbol: "hasInstanceStrict"

T.J. Crowder tj.crowder at farsightsoftware.com
Mon Feb 19 14:25:27 UTC 2018


On Mon, Feb 19, 2018 at 1:59 PM, Александр Ефремов <mr.efrem at gmail.com>
wrote:
>
> A reasons for this proposal:
> 1. I don’t want to use static type checking (Flow or TypeScript)
> because on my experience there more a time spend on the
> describing all types and etc. than it gives favor.
> 2. I want to validate API payloads and other sources of data when
> it’s need.

When [decorators][1] land, provided they land with a means of [decorating
functions][2] (either as part of that proposal or as a follow-on), that
would do the job, wouldn't it? Using your `sum` example:

```js
@rttc(PrimitiveNumber, PrimitiveNumber)
const sum = (a, b) => {
    return a + b;
};
```

...where `rttc` ("runtime type check") decorates the function such that it
does runtime validation of the type of the arguments supplied. (See the
issue referenced in the second link above for why I used a function
expression rather than declration for `sum`.)

-- T.J. Crowder

[1]: https://github.com/tc39/proposal-decorators
[2]: https://github.com/tc39/proposal-decorators/issues/40
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180219/e582d0da/attachment.html>


More information about the es-discuss mailing list