Proposal to add symbol: "hasInstanceStrict"
T.J. Crowder
tj.crowder at farsightsoftware.com
Wed Feb 21 07:50:14 UTC 2018
On Wed, Feb 21, 2018 at 5:15 AM, Александр Ефремов <mr.efrem at gmail.com>
wrote:
>
> I don’t understand how it will be comfortable to write
> decorators for checking arguments of every function with
> different set of arguments:
>
> ```
> function a(b: PrimitiveNumber) {}
>
> function a1({ x: PrimitiveBoolean, d: PrimitiveString }) {}
>
> function a2(e: PrimitiveString, { f: PrimitiveNumber, g: PrimitiveString
}, j: PrimitiveBoolean) {}
> ```
You wouldn't. See my `@rttc` example earlier, it would be something like:
```js
@rttc(PrimitiveNumber)
function a(b) {}
@rttc({ x: PrimitiveBoolean, d: PrimitiveString })
function a1({ x, d }) {}
@rttc(PrimitiveString, { f: PrimitiveNumber, g: PrimitiveString },
PrimitiveBoolean)
function a2(e, { f, g }, j) {}
```
Or perhaps the decorations go on the parameters (avoiding the repetition of
names in the destructuring above), in which case I probably would have a
decorator per typecheck (but the great thing with it being general is you
could choose a parameterized decorator instead):
```js
function a(@primitiveNumber b) {}
function a1({ @primitiveBoolean x, @primitiveString d }) {}
function a2(@primitiveString e, { @primitiveNumber f, @primitiveString g },
@primitiveBoolean j) {}
```
On Wed, Feb 21, 2018 at 5:26 AM, Aleksander Efremov <mr.efrem at gmail.com>
wrote:
>
> I offered use syntax which a lot of developers already know and it
> would be intuitively clear to use it.
It also conflicts with TypeScript's static types (it looks identical, does
something different), so I don't see that being adopted.
-- T.J. Crowder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180221/f35b4ffb/attachment.html>
More information about the es-discuss
mailing list