Proposal to add symbol: "hasInstanceStrict"

Александр Ефремов mr.efrem at gmail.com
Wed Feb 21 08:00:37 UTC 2018



> 21 февр. 2018 г., в 11:50, T.J. Crowder <tj.crowder at farsightsoftware.com> написал(а):
> 
> On Wed, Feb 21, 2018 at 5:15 AM, Александр Ефремов <mr.efrem at gmail.com <mailto: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) {}
> ```
> 

Yes, the last variant is more comfortable, agree.

> On Wed, Feb 21, 2018 at 5:26 AM, Aleksander Efremov <mr.efrem at gmail.com <mailto: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
> 

For locals could be the same variant:

```
@primitiveNumber const a = sum(1, 2);
```

It’s good point!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180221/560d0a2b/attachment-0001.html>


More information about the es-discuss mailing list