Proposal to add symbol: "hasInstanceStrict"

Aleksander Efremov mr.efrem at gmail.com
Mon Feb 19 16:35:37 UTC 2018


How do you offer to check a assignment of result of `fetch` to the variable
(const) ? For it also exists decorator?

19 февр. 2018 г. 18:25 пользователь "T.J. Crowder" <
tj.crowder at farsightsoftware.com> написал:

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/3644f053/attachment-0001.html>


More information about the es-discuss mailing list