@strict class decorator
Not necessarily 100% what you're going for, but you can get an error for
this behavior if you use Object.preventExtensions() on the class, e.g.
class Person {
name;
constructor() {
Object.preventExtensions(this);
}
}
Currently because of an edge-case in Babel 6's class fields, every property would need an initializer value, but that will be fixed in Babel 7. You can see an example here: babeljs.io/repl/#?babili=false&evaluate=true&lineWrap=false&presets=stage-2&targets=&browsers=&builtIns=false&debug=false&code_lz=EQVwzgpgBGAuBOBLAxrYBuAUJ5AbAhmGFAAoTxgD2AdlAN6ZRTX4C20AvFAMxZPI048EKkrwAFAEp6jJlADyAIwBWEVADoADvAgA3CNVgBRAB6wDYRIPGwAFojCT0UWQF9M7nINhRN5KrRc1BAA7qT-NFJYfhQ06vgA5pxQAEwA7OhAA&experimental=false&loose=false&spec=false&playground=false
As for the IDE errors, it doesn't seem like @strict would be enough,
because there are plenty of dynamic ways that you could pass class
constructors or instance objects around that would cause an IDE to lose
track of what objects to look at. This is the type of problem that Flowtype
and Typescript already aim to solve, since the type annotations and
inference allow them to track what types go where. They also already
provide nice IDE errors for just this situation:
www.typescriptlang.org/play/index.html#src= export class Person{ name%3B } const person %3D new Person()%3B person.age %3D 27%3B * flow.org/try/#0PQKgBAAgZgNg9gdzCYAodBTAHgBzgJwBcwBjGAQwGdKwAFDfSuAOwG9UxOxnyBbDANyoAvuhItKxHAybMwAXm4Yk9RiwAUASiHS1zAHTkA5hgVgATAHYBQA
Given the limitations of type inference without an explicit typechecker, it
doesn't seem like an annotation like @strict could be powerful enough to
be useful for an IDE usecase. And for the non-IDE usecase,
Object.preventExtensions seems to do what you want already.
Not necessarily 100% what you're going for, but you can get an error for
this behavior if you use `Object.preventExtensions()` on the class, e.g.
```
class Person {
name;
constructor() {
Object.preventExtensions(this);
}
}
```
Currently because of an edge-case in Babel 6's class fields, every property
would need an initializer value, but that will be fixed in Babel 7. You can
see an example here:
https://babeljs.io/repl/#?babili=false&evaluate=true&lineWrap=false&presets=stage-2&targets=&browsers=&builtIns=false&debug=false&code_lz=EQVwzgpgBGAuBOBLAxrYBuAUJ5AbAhmGFAAoTxgD2AdlAN6ZRTX4C20AvFAMxZPI048EKkrwAFAEp6jJlADyAIwBWEVADoADvAgA3CNVgBRAB6wDYRIPGwAFojCT0UWQF9M7nINhRN5KrRc1BAA7qT-NFJYfhQ06vgA5pxQAEwA7OhAA&experimental=false&loose=false&spec=false&playground=false
As for the IDE errors, it doesn't seem like `@strict` would be enough,
because there are plenty of dynamic ways that you could pass class
constructors or instance objects around that would cause an IDE to lose
track of what objects to look at. This is the type of problem that Flowtype
and Typescript already aim to solve, since the type annotations and
inference allow them to track what types go where. They also already
provide nice IDE errors for just this situation:
*
https://www.typescriptlang.org/play/index.html#src=%0D%0Aexport%20class%20Person%7B%0D%0A%20%20%20%20name%3B%0D%0A%7D%0D%0A%0D%0Aconst%20person%20%3D%20new%20Person()%3B%0D%0Aperson.age%20%3D%2027%3B
*
https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAodBTAHgBzgJwBcwBjGAQwGdKwAFDfSuAOwG9UxOxnyBbDANyoAvuhItKxHAybMwAXm4Yk9RiwAUASiHS1zAHTkA5hgVgATAHYBQA
Given the limitations of type inference without an explicit typechecker, it
doesn't seem like an annotation like `@strict` could be powerful enough to
be useful for an IDE usecase. And for the non-IDE usecase,
`Object.preventExtensions` seems to do what you want already.
On Mon, Aug 7, 2017 at 10:14 PM, Naveen Chawla <naveen.chwl at gmail.com>
wrote:
> So here it is, the holy grail of allowing classes to have fixed
> definitions...
>
> OK what do I mean?
>
> suppose
>
> ```
> @strict
> export class Person{
> name;
> }
> ```
>
> is followed by
>
> ```
> const person = new Person();
> person.age = 27;
> ```
>
> I would like to see the IDE flag it as " "age" is not a property in strict
> class "Person" "
>
> This reminds the developer to then add age as a property, thereby ensuring
> every instance of the class always has full autocomplete, quick property
> renaming etc. across the project, for all properties added to it. For large
> projects with multiple developers this can also have the benefit of
> ensuring that all properties added to each instance are necessarily
> documented in one place, instead of checking whether someone has
> dynamically added a property somewhere.
>
> I would expect this example to throw a runtime exception like @readonly
> does. I don't think that's a problem because I think the IDE would inform
> much sooner. But I'm open to the idea of the runtime allowing it, since the
> real benefit for me is during development. Maybe instead a `@strictDev`
> decorator for that behavior, not sure.
>
> Support?
>
> _______________________________________________
> 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/20170807/5e2507df/attachment.html>For a class which is not intended to be subclassable, this can be done today
with Object.preventExtensions() or Object.seal(), depending on your
intent:
class Foo {
constructor() {
this.bar = 1;
this.baz = 2;
Object.preventExtensions(this);
}
}
const foo = new Foo();
foo.bar = 3; // okay
foo.qux = 4; // throws in strict mode
But this approach doesn’t work when subclassing is or may be in play. It’s also not directly possible with the decorator proposal as it stands today — but there has been discussion of it and it sounds like it’s something that’s on people’s minds:
DE: Omitted features: instance finishers. Yehuda?
YK: an instance finisher is a function that is executed at the end of instantiation of the class at any subclass level and passes at the instance. this is at the end of Reflect.construct. the use case is a decorator to confirm that all instances are frozen or sealed. Another: you want to register created instance into a map. The subclass provides the key, the superclass expresses that the instance should be registered.
DE: instance finishers change how instances are created. It's complicated and so wants to separate it out.
...looking forward to this, too.
Edit: replied before seeing Logan’s response, hence the repetition.
For a class which is not intended to be subclassable, this can be done today
with `Object.preventExtensions()` or `Object.seal()`, depending on your
intent:
class Foo {
constructor() {
this.bar = 1;
this.baz = 2;
Object.preventExtensions(this);
}
}
const foo = new Foo();
foo.bar = 3; // okay
foo.qux = 4; // throws in strict mode
But this approach doesn’t work when subclassing is or may be in play. It’s
also not
directly possible with the decorator proposal as it stands today — but
there has
been discussion of it and it sounds like it’s something that’s on people’s
minds:
[2017 July 27](
http://tc39.github.io/tc39-notes/2017-07_jul-27.html#11ive-interaction-of-privacy-fields-and-decorators
)
> DE: Omitted features: instance finishers. Yehuda?
>
> YK: an instance finisher is a function that is executed at the end of
> instantiation of the class at any subclass level and passes at the
> instance. this is at the end of Reflect.construct. the use case is a
> decorator to confirm that all instances are frozen or sealed. Another:
> you want to register created instance into a map. The subclass provides
> the key, the superclass expresses that the instance should be registered.
>
> DE: instance finishers change how instances are created. It's
> complicated and so wants to separate it out.
...looking forward to this, too.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170808/c46aba3e/attachment.html>Ah great! So then how about having a @seal and/or @preventExtensions
decorator as a shorthand?
I accept that IDEs can only do so much in checking your code, and beyond that, you're on your own...
Secretly I want Javascript to become like TypeScript... all optional, backwards compatible, etc.
Ah great! So then how about having a `@seal` and/or `@preventExtensions`
decorator as a shorthand?
I accept that IDEs can only do so much in checking your code, and beyond
that, you're on your own...
Secretly I want Javascript to become like TypeScript... all optional,
backwards compatible, etc.
On Tue, 8 Aug 2017 at 11:16 Darien Valentine <valentinium at gmail.com> wrote:
> For a class which is not intended to be subclassable, this can be done
> today
> with `Object.preventExtensions()` or `Object.seal()`, depending on your
> intent:
>
> class Foo {
> constructor() {
> this.bar = 1;
> this.baz = 2;
>
> Object.preventExtensions(this);
> }
> }
>
> const foo = new Foo();
>
> foo.bar = 3; // okay
> foo.qux = 4; // throws in strict mode
>
> But this approach doesn’t work when subclassing is or may be in play. It’s
> also not
> directly possible with the decorator proposal as it stands today — but
> there has
> been discussion of it and it sounds like it’s something that’s on people’s
> minds:
>
> [2017 July 27](
> http://tc39.github.io/tc39-notes/2017-07_jul-27.html#11ive-interaction-of-privacy-fields-and-decorators
> )
>
> > DE: Omitted features: instance finishers. Yehuda?
> >
> > YK: an instance finisher is a function that is executed at the end of
> > instantiation of the class at any subclass level and passes at the
> > instance. this is at the end of Reflect.construct. the use case is a
> > decorator to confirm that all instances are frozen or sealed. Another:
> > you want to register created instance into a map. The subclass provides
> > the key, the superclass expresses that the instance should be registered.
> >
> > DE: instance finishers change how instances are created. It's
> > complicated and so wants to separate it out.
>
> ...looking forward to this, too.
> _______________________________________________
> 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/20170808/53dc688c/attachment.html>IIRC, the module core-decorators (a module of utility decorators) have
both of those. That seems ideal, since it's not something that would
massively benefit from being within the standard library itself.
IIRC, the module `core-decorators` (a module of utility decorators) have
both of those. That seems ideal, since it's not something that would
massively benefit from being within the standard library itself.
On Tue, Aug 8, 2017, 02:32 Naveen Chawla <naveen.chwl at gmail.com> wrote:
> Ah great! So then how about having a `@seal` and/or `@preventExtensions`
> decorator as a shorthand?
>
> I accept that IDEs can only do so much in checking your code, and beyond
> that, you're on your own...
>
> Secretly I want Javascript to become like TypeScript... all optional,
> backwards compatible, etc.
>
> On Tue, 8 Aug 2017 at 11:16 Darien Valentine <valentinium at gmail.com>
> wrote:
>
>> For a class which is not intended to be subclassable, this can be done
>> today
>> with `Object.preventExtensions()` or `Object.seal()`, depending on your
>> intent:
>>
>> class Foo {
>> constructor() {
>> this.bar = 1;
>> this.baz = 2;
>>
>> Object.preventExtensions(this);
>> }
>> }
>>
>> const foo = new Foo();
>>
>> foo.bar = 3; // okay
>> foo.qux = 4; // throws in strict mode
>>
>> But this approach doesn’t work when subclassing is or may be in play.
>> It’s also not
>> directly possible with the decorator proposal as it stands today — but
>> there has
>> been discussion of it and it sounds like it’s something that’s on
>> people’s minds:
>>
>> [2017 July 27](
>> http://tc39.github.io/tc39-notes/2017-07_jul-27.html#11ive-interaction-of-privacy-fields-and-decorators
>> )
>>
>> > DE: Omitted features: instance finishers. Yehuda?
>> >
>> > YK: an instance finisher is a function that is executed at the end of
>> > instantiation of the class at any subclass level and passes at the
>> > instance. this is at the end of Reflect.construct. the use case is a
>> > decorator to confirm that all instances are frozen or sealed. Another:
>> > you want to register created instance into a map. The subclass provides
>> > the key, the superclass expresses that the instance should be
>> registered.
>> >
>> > DE: instance finishers change how instances are created. It's
>> > complicated and so wants to separate it out.
>>
>> ...looking forward to this, too.
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
> _______________________________________________
> 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/20170808/18dbfb46/attachment-0001.html>I don't see them. Which ones in core-decorators are they?
Apart from removing a dependency that could be very commonly used, you would be right although I see that as a very compelling case in of itself. I see standard library as a good place for widely useful tasks that span all industry domains. For example, I wouldn't have a library specific to "automotive vehicles" but something that would aid development across the board such as these I think could benefit. Hence why I think they are called "core-decorators"
Hi! I don't see them. Which ones in `core-decorators` are they?
Apart from removing a dependency that could be very commonly used, you
would be right although I see that as a very compelling case in of itself.
I see standard library as a good place for widely useful tasks that span
all industry domains. For example, I wouldn't have a library specific to
"automotive vehicles" but something that would aid development across the
board such as these I think could benefit. Hence why I think they are
called "core-decorators"
On Tue, 8 Aug 2017 at 13:36 Isiah Meadows <isiahmeadows at gmail.com> wrote:
> IIRC, the module `core-decorators` (a module of utility decorators) have
> both of those. That seems ideal, since it's not something that would
> massively benefit from being within the standard library itself.
>
> On Tue, Aug 8, 2017, 02:32 Naveen Chawla <naveen.chwl at gmail.com> wrote:
>
>> Ah great! So then how about having a `@seal` and/or `@preventExtensions`
>> decorator as a shorthand?
>>
>> I accept that IDEs can only do so much in checking your code, and beyond
>> that, you're on your own...
>>
>> Secretly I want Javascript to become like TypeScript... all optional,
>> backwards compatible, etc.
>>
>> On Tue, 8 Aug 2017 at 11:16 Darien Valentine <valentinium at gmail.com>
>> wrote:
>>
>>> For a class which is not intended to be subclassable, this can be done
>>> today
>>> with `Object.preventExtensions()` or `Object.seal()`, depending on your
>>> intent:
>>>
>>> class Foo {
>>> constructor() {
>>> this.bar = 1;
>>> this.baz = 2;
>>>
>>> Object.preventExtensions(this);
>>> }
>>> }
>>>
>>> const foo = new Foo();
>>>
>>> foo.bar = 3; // okay
>>> foo.qux = 4; // throws in strict mode
>>>
>>> But this approach doesn’t work when subclassing is or may be in play.
>>> It’s also not
>>> directly possible with the decorator proposal as it stands today — but
>>> there has
>>> been discussion of it and it sounds like it’s something that’s on
>>> people’s minds:
>>>
>>> [2017 July 27](
>>> http://tc39.github.io/tc39-notes/2017-07_jul-27.html#11ive-interaction-of-privacy-fields-and-decorators
>>> )
>>>
>>> > DE: Omitted features: instance finishers. Yehuda?
>>> >
>>> > YK: an instance finisher is a function that is executed at the end of
>>> > instantiation of the class at any subclass level and passes at the
>>> > instance. this is at the end of Reflect.construct. the use case is a
>>> > decorator to confirm that all instances are frozen or sealed. Another:
>>> > you want to register created instance into a map. The subclass provides
>>> > the key, the superclass expresses that the instance should be
>>> registered.
>>> >
>>> > DE: instance finishers change how instances are created. It's
>>> > complicated and so wants to separate it out.
>>>
>>> ...looking forward to this, too.
>>> _______________________________________________
>>> es-discuss mailing list
>>> es-discuss at mozilla.org
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>> _______________________________________________
>> 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/20170808/398be2e7/attachment.html>I think it might be just @sealed (preventExtensions not available), but
I'm just going off the top of my head. I'd probably recommend it there
rather than in the spec.
I personally see minimal value in it being in the spec proper, because the use case is hardly there, and it's pretty much one line extra in the constructor.
I think it might be just `@sealed` (`preventExtensions` not available), but
I'm just going off the top of my head. I'd probably recommend it there
rather than in the spec.
I personally see minimal value in it being in the spec proper, because the
use case is hardly there, and it's pretty much one line extra in the
constructor.
On Tue, Aug 8, 2017, 04:18 Naveen Chawla <naveen.chwl at gmail.com> wrote:
> Hi! I don't see them. Which ones in `core-decorators` are they?
>
> Apart from removing a dependency that could be very commonly used, you
> would be right although I see that as a very compelling case in of itself.
> I see standard library as a good place for widely useful tasks that span
> all industry domains. For example, I wouldn't have a library specific to
> "automotive vehicles" but something that would aid development across the
> board such as these I think could benefit. Hence why I think they are
> called "core-decorators"
>
> On Tue, 8 Aug 2017 at 13:36 Isiah Meadows <isiahmeadows at gmail.com> wrote:
>
>> IIRC, the module `core-decorators` (a module of utility decorators) have
>> both of those. That seems ideal, since it's not something that would
>> massively benefit from being within the standard library itself.
>>
>> On Tue, Aug 8, 2017, 02:32 Naveen Chawla <naveen.chwl at gmail.com> wrote:
>>
>>> Ah great! So then how about having a `@seal` and/or `@preventExtensions`
>>> decorator as a shorthand?
>>>
>>> I accept that IDEs can only do so much in checking your code, and beyond
>>> that, you're on your own...
>>>
>>> Secretly I want Javascript to become like TypeScript... all optional,
>>> backwards compatible, etc.
>>>
>>> On Tue, 8 Aug 2017 at 11:16 Darien Valentine <valentinium at gmail.com>
>>> wrote:
>>>
>>>> For a class which is not intended to be subclassable, this can be done
>>>> today
>>>> with `Object.preventExtensions()` or `Object.seal()`, depending on your
>>>> intent:
>>>>
>>>> class Foo {
>>>> constructor() {
>>>> this.bar = 1;
>>>> this.baz = 2;
>>>>
>>>> Object.preventExtensions(this);
>>>> }
>>>> }
>>>>
>>>> const foo = new Foo();
>>>>
>>>> foo.bar = 3; // okay
>>>> foo.qux = 4; // throws in strict mode
>>>>
>>>> But this approach doesn’t work when subclassing is or may be in play.
>>>> It’s also not
>>>> directly possible with the decorator proposal as it stands today — but
>>>> there has
>>>> been discussion of it and it sounds like it’s something that’s on
>>>> people’s minds:
>>>>
>>>> [2017 July 27](
>>>> http://tc39.github.io/tc39-notes/2017-07_jul-27.html#11ive-interaction-of-privacy-fields-and-decorators
>>>> )
>>>>
>>>> > DE: Omitted features: instance finishers. Yehuda?
>>>> >
>>>> > YK: an instance finisher is a function that is executed at the end of
>>>> > instantiation of the class at any subclass level and passes at the
>>>> > instance. this is at the end of Reflect.construct. the use case is a
>>>> > decorator to confirm that all instances are frozen or sealed. Another:
>>>> > you want to register created instance into a map. The subclass
>>>> provides
>>>> > the key, the superclass expresses that the instance should be
>>>> registered.
>>>> >
>>>> > DE: instance finishers change how instances are created. It's
>>>> > complicated and so wants to separate it out.
>>>>
>>>> ...looking forward to this, too.
>>>> _______________________________________________
>>>> es-discuss mailing list
>>>> es-discuss at mozilla.org
>>>> https://mail.mozilla.org/listinfo/es-discuss
>>>>
>>> _______________________________________________
>>> 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/20170808/7262cfad/attachment.html>Nope not there (according to a Co+F keyboard search!)
Use case is any time someone wants basic strict typing during development, but I agree it's not quite as compelling as if/when types in params (e.g. : Person) are introduced in Javascript (which I'd like honestly)
Nope not there (according to a Co+F keyboard search!)
Use case is any time someone wants basic strict typing during development,
but I agree it's not quite as compelling as if/when types in params (e.g. :
Person) are introduced in Javascript (which I'd like honestly)
On Tue, 8 Aug 2017 at 13:52 Isiah Meadows <isiahmeadows at gmail.com> wrote:
> I think it might be just `@sealed` (`preventExtensions` not available),
> but I'm just going off the top of my head. I'd probably recommend it there
> rather than in the spec.
>
> I personally see minimal value in it being in the spec proper, because the
> use case is hardly there, and it's pretty much one line extra in the
> constructor.
>
> On Tue, Aug 8, 2017, 04:18 Naveen Chawla <naveen.chwl at gmail.com> wrote:
>
>> Hi! I don't see them. Which ones in `core-decorators` are they?
>>
>> Apart from removing a dependency that could be very commonly used, you
>> would be right although I see that as a very compelling case in of itself.
>> I see standard library as a good place for widely useful tasks that span
>> all industry domains. For example, I wouldn't have a library specific to
>> "automotive vehicles" but something that would aid development across the
>> board such as these I think could benefit. Hence why I think they are
>> called "core-decorators"
>>
>> On Tue, 8 Aug 2017 at 13:36 Isiah Meadows <isiahmeadows at gmail.com> wrote:
>>
>>> IIRC, the module `core-decorators` (a module of utility decorators) have
>>> both of those. That seems ideal, since it's not something that would
>>> massively benefit from being within the standard library itself.
>>>
>>> On Tue, Aug 8, 2017, 02:32 Naveen Chawla <naveen.chwl at gmail.com> wrote:
>>>
>>>> Ah great! So then how about having a `@seal` and/or
>>>> `@preventExtensions` decorator as a shorthand?
>>>>
>>>> I accept that IDEs can only do so much in checking your code, and
>>>> beyond that, you're on your own...
>>>>
>>>> Secretly I want Javascript to become like TypeScript... all optional,
>>>> backwards compatible, etc.
>>>>
>>>> On Tue, 8 Aug 2017 at 11:16 Darien Valentine <valentinium at gmail.com>
>>>> wrote:
>>>>
>>>>> For a class which is not intended to be subclassable, this can be done
>>>>> today
>>>>> with `Object.preventExtensions()` or `Object.seal()`, depending on
>>>>> your intent:
>>>>>
>>>>> class Foo {
>>>>> constructor() {
>>>>> this.bar = 1;
>>>>> this.baz = 2;
>>>>>
>>>>> Object.preventExtensions(this);
>>>>> }
>>>>> }
>>>>>
>>>>> const foo = new Foo();
>>>>>
>>>>> foo.bar = 3; // okay
>>>>> foo.qux = 4; // throws in strict mode
>>>>>
>>>>> But this approach doesn’t work when subclassing is or may be in play.
>>>>> It’s also not
>>>>> directly possible with the decorator proposal as it stands today — but
>>>>> there has
>>>>> been discussion of it and it sounds like it’s something that’s on
>>>>> people’s minds:
>>>>>
>>>>> [2017 July 27](
>>>>> http://tc39.github.io/tc39-notes/2017-07_jul-27.html#11ive-interaction-of-privacy-fields-and-decorators
>>>>> )
>>>>>
>>>>> > DE: Omitted features: instance finishers. Yehuda?
>>>>> >
>>>>> > YK: an instance finisher is a function that is executed at the end of
>>>>> > instantiation of the class at any subclass level and passes at the
>>>>> > instance. this is at the end of Reflect.construct. the use case is a
>>>>> > decorator to confirm that all instances are frozen or sealed.
>>>>> Another:
>>>>> > you want to register created instance into a map. The subclass
>>>>> provides
>>>>> > the key, the superclass expresses that the instance should be
>>>>> registered.
>>>>> >
>>>>> > DE: instance finishers change how instances are created. It's
>>>>> > complicated and so wants to separate it out.
>>>>>
>>>>> ...looking forward to this, too.
>>>>> _______________________________________________
>>>>> es-discuss mailing list
>>>>> es-discuss at mozilla.org
>>>>> https://mail.mozilla.org/listinfo/es-discuss
>>>>>
>>>> _______________________________________________
>>>> 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/20170808/ba8a3d8d/attachment-0001.html>Yeah, I would've checked had I been on a computer, not a phone... ;-)
Out of curiosity, though, what do you mean by if/when types? I don't recall hearing about it.
Yeah, I would've checked had I been on a computer, not a phone... ;-)
Out of curiosity, though, what do you mean by if/when types? I don't recall
hearing about it.
On Tue, Aug 8, 2017, 04:30 Naveen Chawla <naveen.chwl at gmail.com> wrote:
> Nope not there (according to a Co+F keyboard search!)
>
> Use case is any time someone wants basic strict typing during development,
> but I agree it's not quite as compelling as if/when types in params (e.g. :
> Person) are introduced in Javascript (which I'd like honestly)
>
> On Tue, 8 Aug 2017 at 13:52 Isiah Meadows <isiahmeadows at gmail.com> wrote:
>
>> I think it might be just `@sealed` (`preventExtensions` not available),
>> but I'm just going off the top of my head. I'd probably recommend it there
>> rather than in the spec.
>>
>> I personally see minimal value in it being in the spec proper, because
>> the use case is hardly there, and it's pretty much one line extra in the
>> constructor.
>>
>> On Tue, Aug 8, 2017, 04:18 Naveen Chawla <naveen.chwl at gmail.com> wrote:
>>
>>> Hi! I don't see them. Which ones in `core-decorators` are they?
>>>
>>> Apart from removing a dependency that could be very commonly used, you
>>> would be right although I see that as a very compelling case in of itself.
>>> I see standard library as a good place for widely useful tasks that span
>>> all industry domains. For example, I wouldn't have a library specific to
>>> "automotive vehicles" but something that would aid development across the
>>> board such as these I think could benefit. Hence why I think they are
>>> called "core-decorators"
>>>
>>> On Tue, 8 Aug 2017 at 13:36 Isiah Meadows <isiahmeadows at gmail.com>
>>> wrote:
>>>
>>>> IIRC, the module `core-decorators` (a module of utility decorators)
>>>> have both of those. That seems ideal, since it's not something that would
>>>> massively benefit from being within the standard library itself.
>>>>
>>>> On Tue, Aug 8, 2017, 02:32 Naveen Chawla <naveen.chwl at gmail.com> wrote:
>>>>
>>>>> Ah great! So then how about having a `@seal` and/or
>>>>> `@preventExtensions` decorator as a shorthand?
>>>>>
>>>>> I accept that IDEs can only do so much in checking your code, and
>>>>> beyond that, you're on your own...
>>>>>
>>>>> Secretly I want Javascript to become like TypeScript... all optional,
>>>>> backwards compatible, etc.
>>>>>
>>>>> On Tue, 8 Aug 2017 at 11:16 Darien Valentine <valentinium at gmail.com>
>>>>> wrote:
>>>>>
>>>>>> For a class which is not intended to be subclassable, this can be
>>>>>> done today
>>>>>> with `Object.preventExtensions()` or `Object.seal()`, depending on
>>>>>> your intent:
>>>>>>
>>>>>> class Foo {
>>>>>> constructor() {
>>>>>> this.bar = 1;
>>>>>> this.baz = 2;
>>>>>>
>>>>>> Object.preventExtensions(this);
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> const foo = new Foo();
>>>>>>
>>>>>> foo.bar = 3; // okay
>>>>>> foo.qux = 4; // throws in strict mode
>>>>>>
>>>>>> But this approach doesn’t work when subclassing is or may be in play.
>>>>>> It’s also not
>>>>>> directly possible with the decorator proposal as it stands today —
>>>>>> but there has
>>>>>> been discussion of it and it sounds like it’s something that’s on
>>>>>> people’s minds:
>>>>>>
>>>>>> [2017 July 27](
>>>>>> http://tc39.github.io/tc39-notes/2017-07_jul-27.html#11ive-interaction-of-privacy-fields-and-decorators
>>>>>> )
>>>>>>
>>>>>> > DE: Omitted features: instance finishers. Yehuda?
>>>>>> >
>>>>>> > YK: an instance finisher is a function that is executed at the end
>>>>>> of
>>>>>> > instantiation of the class at any subclass level and passes at the
>>>>>> > instance. this is at the end of Reflect.construct. the use case is a
>>>>>> > decorator to confirm that all instances are frozen or sealed.
>>>>>> Another:
>>>>>> > you want to register created instance into a map. The subclass
>>>>>> provides
>>>>>> > the key, the superclass expresses that the instance should be
>>>>>> registered.
>>>>>> >
>>>>>> > DE: instance finishers change how instances are created. It's
>>>>>> > complicated and so wants to separate it out.
>>>>>>
>>>>>> ...looking forward to this, too.
>>>>>> _______________________________________________
>>>>>> es-discuss mailing list
>>>>>> es-discuss at mozilla.org
>>>>>> https://mail.mozilla.org/listinfo/es-discuss
>>>>>>
>>>>> _______________________________________________
>>>>> 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/20170808/b09f5169/attachment.html>Sorry my writing style was bad. I meant if or when there is an introduction
of types in parameters (like in ActionScript, TypeScript etc.) e,g,
sayHelloToPerson(person : Person); which I said I'd like
Sorry my writing style was bad. I meant if or when there is an introduction
of types in parameters (like in ActionScript, TypeScript etc.) e,g,
`sayHelloToPerson(person : Person);` which I said I'd like
On Tue, 8 Aug 2017 at 14:02 Isiah Meadows <isiahmeadows at gmail.com> wrote:
> Yeah, I would've checked had I been on a computer, not a phone... ;-)
>
> Out of curiosity, though, what do you mean by if/when types? I don't
> recall hearing about it.
>
> On Tue, Aug 8, 2017, 04:30 Naveen Chawla <naveen.chwl at gmail.com> wrote:
>
>> Nope not there (according to a Co+F keyboard search!)
>>
>> Use case is any time someone wants basic strict typing during
>> development, but I agree it's not quite as compelling as if/when types in
>> params (e.g. : Person) are introduced in Javascript (which I'd like
>> honestly)
>>
>> On Tue, 8 Aug 2017 at 13:52 Isiah Meadows <isiahmeadows at gmail.com> wrote:
>>
>>> I think it might be just `@sealed` (`preventExtensions` not available),
>>> but I'm just going off the top of my head. I'd probably recommend it there
>>> rather than in the spec.
>>>
>>> I personally see minimal value in it being in the spec proper, because
>>> the use case is hardly there, and it's pretty much one line extra in the
>>> constructor.
>>>
>>> On Tue, Aug 8, 2017, 04:18 Naveen Chawla <naveen.chwl at gmail.com> wrote:
>>>
>>>> Hi! I don't see them. Which ones in `core-decorators` are they?
>>>>
>>>> Apart from removing a dependency that could be very commonly used, you
>>>> would be right although I see that as a very compelling case in of itself.
>>>> I see standard library as a good place for widely useful tasks that span
>>>> all industry domains. For example, I wouldn't have a library specific to
>>>> "automotive vehicles" but something that would aid development across the
>>>> board such as these I think could benefit. Hence why I think they are
>>>> called "core-decorators"
>>>>
>>>> On Tue, 8 Aug 2017 at 13:36 Isiah Meadows <isiahmeadows at gmail.com>
>>>> wrote:
>>>>
>>>>> IIRC, the module `core-decorators` (a module of utility decorators)
>>>>> have both of those. That seems ideal, since it's not something that would
>>>>> massively benefit from being within the standard library itself.
>>>>>
>>>>> On Tue, Aug 8, 2017, 02:32 Naveen Chawla <naveen.chwl at gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Ah great! So then how about having a `@seal` and/or
>>>>>> `@preventExtensions` decorator as a shorthand?
>>>>>>
>>>>>> I accept that IDEs can only do so much in checking your code, and
>>>>>> beyond that, you're on your own...
>>>>>>
>>>>>> Secretly I want Javascript to become like TypeScript... all optional,
>>>>>> backwards compatible, etc.
>>>>>>
>>>>>> On Tue, 8 Aug 2017 at 11:16 Darien Valentine <valentinium at gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> For a class which is not intended to be subclassable, this can be
>>>>>>> done today
>>>>>>> with `Object.preventExtensions()` or `Object.seal()`, depending on
>>>>>>> your intent:
>>>>>>>
>>>>>>> class Foo {
>>>>>>> constructor() {
>>>>>>> this.bar = 1;
>>>>>>> this.baz = 2;
>>>>>>>
>>>>>>> Object.preventExtensions(this);
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> const foo = new Foo();
>>>>>>>
>>>>>>> foo.bar = 3; // okay
>>>>>>> foo.qux = 4; // throws in strict mode
>>>>>>>
>>>>>>> But this approach doesn’t work when subclassing is or may be in
>>>>>>> play. It’s also not
>>>>>>> directly possible with the decorator proposal as it stands today —
>>>>>>> but there has
>>>>>>> been discussion of it and it sounds like it’s something that’s on
>>>>>>> people’s minds:
>>>>>>>
>>>>>>> [2017 July 27](
>>>>>>> http://tc39.github.io/tc39-notes/2017-07_jul-27.html#11ive-interaction-of-privacy-fields-and-decorators
>>>>>>> )
>>>>>>>
>>>>>>> > DE: Omitted features: instance finishers. Yehuda?
>>>>>>> >
>>>>>>> > YK: an instance finisher is a function that is executed at the end
>>>>>>> of
>>>>>>> > instantiation of the class at any subclass level and passes at the
>>>>>>> > instance. this is at the end of Reflect.construct. the use case is
>>>>>>> a
>>>>>>> > decorator to confirm that all instances are frozen or sealed.
>>>>>>> Another:
>>>>>>> > you want to register created instance into a map. The subclass
>>>>>>> provides
>>>>>>> > the key, the superclass expresses that the instance should be
>>>>>>> registered.
>>>>>>> >
>>>>>>> > DE: instance finishers change how instances are created. It's
>>>>>>> > complicated and so wants to separate it out.
>>>>>>>
>>>>>>> ...looking forward to this, too.
>>>>>>> _______________________________________________
>>>>>>> es-discuss mailing list
>>>>>>> es-discuss at mozilla.org
>>>>>>> https://mail.mozilla.org/listinfo/es-discuss
>>>>>>>
>>>>>> _______________________________________________
>>>>>> 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/20170808/6be32303/attachment.html>An HTML attachment was scrubbed... URL: esdiscuss/attachments/20170808/0effcda7/attachment
An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170808/0effcda7/attachment.html>
Name changes are fine but the type would remain the same, right?
Name changes are fine but the type would remain the same, right?
On Tue, 8 Aug 2017 at 18:22 Sebastian Malton <sebastian at malton.name> wrote:
> That does sound very useful however it has to work (somehow) with NodeJS
> where the name of objects can change through requiring. Would the type be
> the original name or the name in the current file?
>
> *From:* naveen.chwl at gmail.com
> *Sent:* August 8, 2017 4:59 AM
> *To:* isiahmeadows at gmail.com; valentinium at gmail.com;
> es-discuss at mozilla.org
> *Subject:* Re: Re: @strict class decorator
>
> Sorry my writing style was bad. I meant if or when there is an
> introduction of types in parameters (like in ActionScript, TypeScript etc.)
> e,g, `sayHelloToPerson(person : Person);` which I said I'd like
>
> On Tue, 8 Aug 2017 at 14:02 Isiah Meadows <isiahmeadows at gmail.com> wrote:
>
>> Yeah, I would've checked had I been on a computer, not a phone... ;-)
>>
>> Out of curiosity, though, what do you mean by if/when types? I don't
>> recall hearing about it.
>>
>> On Tue, Aug 8, 2017, 04:30 Naveen Chawla <naveen.chwl at gmail.com> wrote:
>>
>>> Nope not there (according to a Co+F keyboard search!)
>>>
>>> Use case is any time someone wants basic strict typing during
>>> development, but I agree it's not quite as compelling as if/when types in
>>> params (e.g. : Person) are introduced in Javascript (which I'd like
>>> honestly)
>>>
>>> On Tue, 8 Aug 2017 at 13:52 Isiah Meadows <isiahmeadows at gmail.com>
>>> wrote:
>>>
>>>> I think it might be just `@sealed` (`preventExtensions` not available),
>>>> but I'm just going off the top of my head. I'd probably recommend it there
>>>> rather than in the spec.
>>>>
>>>> I personally see minimal value in it being in the spec proper, because
>>>> the use case is hardly there, and it's pretty much one line extra in the
>>>> constructor.
>>>>
>>>> On Tue, Aug 8, 2017, 04:18 Naveen Chawla <naveen.chwl at gmail.com> wrote:
>>>>
>>>>> Hi! I don't see them. Which ones in `core-decorators` are they?
>>>>>
>>>>> Apart from removing a dependency that could be very commonly used, you
>>>>> would be right although I see that as a very compelling case in of itself.
>>>>> I see standard library as a good place for widely useful tasks that span
>>>>> all industry domains. For example, I wouldn't have a library specific to
>>>>> "automotive vehicles" but something that would aid development across the
>>>>> board such as these I think could benefit. Hence why I think they are
>>>>> called "core-decorators"
>>>>>
>>>>> On Tue, 8 Aug 2017 at 13:36 Isiah Meadows <isiahmeadows at gmail.com>
>>>>> wrote:
>>>>>
>>>>>> IIRC, the module `core-decorators` (a module of utility decorators)
>>>>>> have both of those. That seems ideal, since it's not something that would
>>>>>> massively benefit from being within the standard library itself.
>>>>>>
>>>>>> On Tue, Aug 8, 2017, 02:32 Naveen Chawla <naveen.chwl at gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Ah great! So then how about having a `@seal` and/or
>>>>>>> `@preventExtensions` decorator as a shorthand?
>>>>>>>
>>>>>>> I accept that IDEs can only do so much in checking your code, and
>>>>>>> beyond that, you're on your own...
>>>>>>>
>>>>>>> Secretly I want Javascript to become like TypeScript... all
>>>>>>> optional, backwards compatible, etc.
>>>>>>>
>>>>>>> On Tue, 8 Aug 2017 at 11:16 Darien Valentine <valentinium at gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> For a class which is not intended to be subclassable, this can be
>>>>>>>> done today
>>>>>>>> with `Object.preventExtensions()` or `Object.seal()`, depending on
>>>>>>>> your intent:
>>>>>>>>
>>>>>>>> class Foo {
>>>>>>>> constructor() {
>>>>>>>> this.bar = 1;
>>>>>>>> this.baz = 2;
>>>>>>>>
>>>>>>>> Object.preventExtensions(this);
>>>>>>>> }
>>>>>>>> }
>>>>>>>>
>>>>>>>> const foo = new Foo();
>>>>>>>>
>>>>>>>> foo.bar = 3; // okay
>>>>>>>> foo.qux = 4; // throws in strict mode
>>>>>>>>
>>>>>>>> But this approach doesn’t work when subclassing is or may be in
>>>>>>>> play. It’s also not
>>>>>>>> directly possible with the decorator proposal as it stands today —
>>>>>>>> but there has
>>>>>>>> been discussion of it and it sounds like it’s something that’s on
>>>>>>>> people’s minds:
>>>>>>>>
>>>>>>>> [2017 July 27](
>>>>>>>> http://tc39.github.io/tc39-notes/2017-07_jul-27.html#11ive-interaction-of-privacy-fields-and-decorators
>>>>>>>> )
>>>>>>>>
>>>>>>>> > DE: Omitted features: instance finishers. Yehuda?
>>>>>>>> >
>>>>>>>> > YK: an instance finisher is a function that is executed at the
>>>>>>>> end of
>>>>>>>> > instantiation of the class at any subclass level and passes at the
>>>>>>>> > instance. this is at the end of Reflect.construct. the use case
>>>>>>>> is a
>>>>>>>> > decorator to confirm that all instances are frozen or sealed.
>>>>>>>> Another:
>>>>>>>> > you want to register created instance into a map. The subclass
>>>>>>>> provides
>>>>>>>> > the key, the superclass expresses that the instance should be
>>>>>>>> registered.
>>>>>>>> >
>>>>>>>> > DE: instance finishers change how instances are created. It's
>>>>>>>> > complicated and so wants to separate it out.
>>>>>>>>
>>>>>>>> ...looking forward to this, too.
>>>>>>>> _______________________________________________
>>>>>>>> es-discuss mailing list
>>>>>>>> es-discuss at mozilla.org
>>>>>>>> https://mail.mozilla.org/listinfo/es-discuss
>>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> 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/20170808/4beb8565/attachment-0001.html>Subclassing can work too.
class A {
constructor() {
this.bar = 1;
this.baz = 2;
if (new.target === A) Object.preventExtensions(this);
}
}
class B extends A {
constructor() {
super();
this.bat = 3;
if (new.target === B) Object.preventExtensions(this);
}
}
No decorator needed to do this today.
I am not keeping up with decorators but @sealed implies to me that the class cannot be subclassed? At least that's what it means in C# and would confuse me if it simply meant Object.seal(this)...
Subclassing can work too.
```js
class A {
constructor() {
this.bar = 1;
this.baz = 2;
if (new.target === A) Object.preventExtensions(this);
}
}
class B extends A {
constructor() {
super();
this.bat = 3;
if (new.target === B) Object.preventExtensions(this);
}
}
```
No decorator needed to do this today.
I am not keeping up with decorators but @sealed implies to me that the
class cannot be subclassed? At least that's what it means in C# and would
confuse me if it simply meant Object.seal(this)...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170808/7179fe17/attachment.html>
So here it is, the holy grail of allowing classes to have fixed definitions...
OK what do I mean?
suppose
is followed by
I would like to see the IDE flag it as " "age" is not a property in strict class "Person" "
This reminds the developer to then add age as a property, thereby ensuring every instance of the class always has full autocomplete, quick property renaming etc. across the project, for all properties added to it. For large projects with multiple developers this can also have the benefit of ensuring that all properties added to each instance are necessarily documented in one place, instead of checking whether someone has dynamically added a property somewhere.
I would expect this example to throw a runtime exception like @readonly does. I don't think that's a problem because I think the IDE would inform much sooner. But I'm open to the idea of the runtime allowing it, since the real benefit for me is during development. Maybe instead a
@strictDevdecorator for that behavior, not sure.Support?
So here it is, the holy grail of allowing classes to have fixed definitions... OK what do I mean? suppose ``` @strict export class Person{ name; } ``` is followed by ``` const person = new Person(); person.age = 27; ``` I would like to see the IDE flag it as " "age" is not a property in strict class "Person" " This reminds the developer to then add age as a property, thereby ensuring every instance of the class always has full autocomplete, quick property renaming etc. across the project, for all properties added to it. For large projects with multiple developers this can also have the benefit of ensuring that all properties added to each instance are necessarily documented in one place, instead of checking whether someone has dynamically added a property somewhere. I would expect this example to throw a runtime exception like @readonly does. I don't think that's a problem because I think the IDE would inform much sooner. But I'm open to the idea of the runtime allowing it, since the real benefit for me is during development. Maybe instead a `@strictDev` decorator for that behavior, not sure. Support? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170808/7bcb1afb/attachment.html>