Re: Re: What do you think about a C# 6 like nameof() expression for

Can you list the benefits of having this operators? Maybe with example use cases

If I understand it correctly, the operator fits better in compiled
(and typed) languages, most of the use cases don't apply to dynamic
Javascript
The only legit use case I can think of is helping refactor tools to
rename properties (but even mismatch errors between strings and
properties names can be caught in compile time using modern
Typescript)

Re: Re: What do you think about a C# 6 like nameof() expression for

Have not tried TypeScript. What are the use cases for JavaScript where TypeScript is not used? Does ```nameof()``` check if an object has a specific property name defined (```"MutationObserver" in window```; ```window.MutationObserver```; ```"document" in globalThis```)?

Re: Re: What do you think about a C# 6 like nameof() expression for

The 'nameof' operator provides the string name of a static symbol (in compiler/linker terms, not an ECMAScript 'Symbol'). This is often useful for diagnostics (logging and errors), and gives developers a way to reduce repetition. It is also extremely helpful
in editors that support symbolic "rename" refactoring.

While ES functions have a 'name' property, one of the main use cases is to get a string representation of the name of a thing that isn't itself reified as an object, such as a variable, parameter, or module namespace:

```

import * as ns from "foo";

nameof ns; // "ns"

let fn = function g() {};

fn.name; // "g"

nameof fn; // "fn"

```

Here is an example of two common use cases:

```

class C {

compare(other) {

if (!(other instanceof C)) {

throw new TypeError(`Invalid argument: ${nameof other} `);

}

set prop(value) {

this._prop = value;

this.emit("propertychanged", nameof prop);

}

}

```

It's not that a language like TypeScript would need this, but rather that users of an editor like VS Code or WebStorm that have a JavaScript language service would benefit from it.

Ron

From: es-discuss <[hidden email]> on behalf of guest271314 <[hidden email]>Sent: Friday, June 14, 2019 9:05:55 AMTo: Stas BerkovCc:[hidden email]Subject: Re: Re: What do you think about a C# 6 like nameof() expression for

Have not tried TypeScript. What are the use cases for JavaScript where TypeScript is not used? Does ```nameof()``` check if an object has a specific property name defined (```"MutationObserver" in window```; ```window.MutationObserver```; ```"document"
in globalThis```)?

The 'nameof' operator provides the string name of a static symbol (in compiler/linker terms, not an ECMAScript 'Symbol'). This is often useful for diagnostics (logging and errors), and gives developers a way to reduce repetition. It is also extremely helpful
in editors that support symbolic "rename" refactoring.

While ES functions have a 'name' property, one of the main use cases is to get a string representation of the name of a thing that isn't itself reified as an object, such as a variable, parameter, or module namespace:

It's not that a language like TypeScript would need this, but rather that users of an editor like VS Code or WebStorm that have a JavaScript language service would benefit from it.

Ron

From: es-discuss <[hidden email]> on behalf of guest271314 <[hidden email]>Sent: Friday, June 14, 2019 9:05:55 AMTo: Stas BerkovCc:[hidden email]Subject: Re: Re: What do you think about a C# 6 like nameof() expression for

Have not tried TypeScript. What are the use cases for JavaScript where TypeScript is not used? Does ```nameof()``` check if an object has a specific property name defined (```"MutationObserver" in window```; ```window.MutationObserver```; ```"document"
in globalThis```)?

Can you list the benefits of having this operators? Maybe with example use cases

If I understand it correctly, the operator fits better in compiled
(and typed) languages, most of the use cases don't apply to dynamic
Javascript
The only legit use case I can think of is helping refactor tools to
rename properties (but even mismatch errors between strings and
properties names can be caught in compile time using modern
Typescript)

Can you list the benefits of having this operators? Maybe with example use cases

If I understand it correctly, the operator fits better in compiled
(and typed) languages, most of the use cases don't apply to dynamic
Javascript
The only legit use case I can think of is helping refactor tools to
rename properties (but even mismatch errors between strings and
properties names can be caught in compile time using modern
Typescript)

Can you list the benefits of having this operators? Maybe with example use cases

If I understand it correctly, the operator fits better in compiled
(and typed) languages, most of the use cases don't apply to dynamic
Javascript
The only legit use case I can think of is helping refactor tools to
rename properties (but even mismatch errors between strings and
properties names can be caught in compile time using modern
Typescript)

Can you list the benefits of having this operators? Maybe with example use cases

If I understand it correctly, the operator fits better in compiled
(and typed) languages, most of the use cases don't apply to dynamic
Javascript
The only legit use case I can think of is helping refactor tools to
rename properties (but even mismatch errors between strings and
properties names can be caught in compile time using modern
Typescript)

For users that roll their own code by hand at a text editor and do not use an IDE for composing code (or relying on an IDE for logging errors), am not able to discern how ```nameof``` is different than using ```Object.getOwnPropertyDescriptors(other).name.value``` or ```Object.keys({userName})[0]```. The actual code will need to be tested in different browsers anyway before deployment to get the actual results.

If a user has decided they _have_ to use some form of a dynamic "IDE" to compose code and log errors - while they are writing the code, they can open DevTools at Chromium or Chrome then select ```Sources``` => ```Snippets``` => ```New snippet```, where

```

const n = 123;const n = 456;

```

will highlight the line where the error occurs - during writing the code - the as a red circle with a transparent "x" in the middle

Can you list the benefits of having this operators? Maybe with example use cases

If I understand it correctly, the operator fits better in compiled
(and typed) languages, most of the use cases don't apply to dynamic
Javascript
The only legit use case I can think of is helping refactor tools to
rename properties (but even mismatch errors between strings and
properties names can be caught in compile time using modern
Typescript)

RE: Re: What do you think about a C# 6 like nameof() expression for

A module namespace isn’t an instance of `Module`, it’s a module namespace spec object. If it has a `name` member, that is because the module you imported has an exported binding called `name`. But what kind of thing it is isn’t what matters.

`nameof` just returns a string representation of the static symbolic name of its operand. `nameof` would be used at runtime (i.e. during code execution), but provides the ability for advanced editors to include it in a “rename” refactoring.

The operand merely needs to be an identifier that exists within the current lexical scope. `nameof` would not observe TDZ and would not evaluate any expression. The ECMAScript static semantics would merely: 1) check that the identifier
provided to `nameof` is the name of something in the current lexical scope, and 2) replace the expression with a string literal representing the name.

If `nameof foo.bar` were allowed `nameof` would not actually evaluate `foo.bar`, but merely result in `”bar”`. `nameof` does not evaluate anything, it is merely a syntactic transformation by the runtime that becomes a string.

The 'nameof' operator provides the string name of a static symbol (in compiler/linker terms, not an ECMAScript 'Symbol'). This is often useful for diagnostics
(logging and errors), and gives developers a way to reduce repetition. It is also extremely helpful in editors that support symbolic "rename" refactoring.

While ES functions have a 'name' property, one of the main use cases is to get a string representation of the name of a thing that isn't itself reified
as an object, such as a variable, parameter, or module namespace:

It's not that a language like TypeScript would need this, but rather that users of an editor like VS Code or WebStorm that have a JavaScript language
service would benefit from it.

Ron

From: es-discuss <[hidden email]> on behalf of guest271314 <[hidden email]>Sent: Friday, June 14, 2019 9:05:55 AMTo: Stas BerkovCc:[hidden email]Subject: Re: Re: What do you think about a C# 6 like nameof() expression for

Have not tried TypeScript. What are the use cases for JavaScript where TypeScript is not used? Does ```nameof()``` check if an object has a specific property name defined (```"MutationObserver" in window```; ```window.MutationObserver```;
```"document" in globalThis```)?

For users that roll their own code by hand at a text editor and do not use an IDE for composing code (or relying on an IDE for logging errors), am not able to discern how ```nameof``` is different than using ```Object.getOwnPropertyDescriptors(other).name.value```
or ```Object.keys({userName})[0]```. The actual code will need to be tested in different browsers anyway before deployment to get the actual results.

If a user has decided they _have_ to use some form of a dynamic "IDE" to compose code and log errors - while they are writing the code, they can open DevTools at Chromium or Chrome then select ```Sources``` => ```Snippets``` => ```New snippet```, where

```

const n = 123;
const n = 456;

```

will highlight the line where the error occurs - during writing the code - the as a red circle with a transparent "x" in the middle

Can you list the benefits of having this operators? Maybe with example use cases

If I understand it correctly, the operator fits better in compiled
(and typed) languages, most of the use cases don't apply to dynamic
Javascript
The only legit use case I can think of is helping refactor tools to
rename properties (but even mismatch errors between strings and
properties names can be caught in compile time using modern
Typescript)

Re: Re: What do you think about a C# 6 like nameof() expression for

> A module namespace isn’t an instance of Module, it’s a module namespace spec object. If it has a name member, that is because the module you imported has an exported binding called name. But what kind of thing it is isn’t what matters.

If ```Object.getOwnPropertyDescriptors(ns)``` is used within ```<script type="module">``` ```Symbol(Symbol.toStringTag): {value: "Module", writable: false, enumerable: false, configurable: false}``` will also be part of the output. If ```Object.keys(ns)``` is used ```Symbol(Symbol.toStringTag)``` will not be part of output.

> Since ```nameof``` does not actually evaluate anything, the following would be legal:

> ```> const x = nameof y; // "y"> const y = 1;> ```

Interesting. ```y``` would be able to be evaluated before ```y``` is defined?

Can you list the benefits of having this operators? Maybe with example use cases

If I understand it correctly, the operator fits better in compiled
(and typed) languages, most of the use cases don't apply to dynamic
Javascript
The only legit use case I can think of is helping refactor tools to
rename properties (but even mismatch errors between strings and
properties names can be caught in compile time using modern
Typescript)

Re: Re: What do you think about a C# 6 like nameof() expression for

Am neither for nor against the proposal. Do not entertain "like"s or "dislike"s in any field of endeavor. Am certainly not in a position to prohibit anything relevant JavaScript. Do what thou wilt shall be the whole of the Law.

Have yet to view a case where code will be "broken" by ```nameof``` not being a JavaScript feature. "robustness", as already mentioned, is a subjective adjective that is not capable of being objectively evaluated as to code itself. That description is based on preference or choice.

In lieu of the proposal being specificed, use the posted code example of ```Object.keys()``` that "works".

provides a direct indication that the property value is required to be defined. Note that the example code posted thus far does not first check if ```options``` is passed at all, for which ```nameof``` will not provide any asssitance.

Usually try to meet requirement by means already available in FOSS browsers. Have no interest in TypeScript or using an IDE.

RE: Re: What do you think about a C# 6 like nameof() expression for

> Interesting. ```y``` would be able to be evaluated before ```y``` is defined?

I very explicitly stated that `nameof y` would *not* evaluate its operand. Evaluation of `nameof` would merely result in a string containing the name of the binding referenced by the operand.

From: es-discuss <[hidden email]>
On Behalf Of guest271314Sent: Friday, June 14, 2019 12:09 PMTo: Stas Berkov <[hidden email]>Cc:[hidden email]Subject: Re: Re: What do you think about a C# 6 like nameof() expression for

> A module namespace isn’t an instance of Module,
it’s a module namespace spec object. If it has a name member, that is because
the module you imported has an exported binding called name. But what kind
of thing it is isn’t what matters.

If ```Object.getOwnPropertyDescriptors(ns)``` is used within ```<script type="module">``` ```Symbol(Symbol.toStringTag): {value: "Module", writable: false, enumerable: false, configurable: false}``` will also be part of the output. If ```Object.keys(ns)```
is used ```Symbol(Symbol.toStringTag)``` will not be part of output.

> Since ```nameof``` does not actually evaluate anything, the following would be legal:

> ```
> const x = nameof y; // "y"
> const y = 1;
> ```

Interesting. ```y``` would be able to be evaluated before ```y``` is defined?

Can you list the benefits of having this operators? Maybe with example use cases

If I understand it correctly, the operator fits better in compiled
(and typed) languages, most of the use cases don't apply to dynamic
Javascript
The only legit use case I can think of is helping refactor tools to
rename properties (but even mismatch errors between strings and
properties names can be caught in compile time using modern
Typescript)

Re: Re: What do you think about a C# 6 like nameof() expression for

`nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused why it'd be better to type `nameof foo` in code, rather than `'foo'` - if you change `foo` to `bar`, you have to change both of them anyways.

Am neither for nor against the proposal. Do not entertain "like"s or "dislike"s in any field of endeavor. Am certainly not in a position to prohibit anything relevant JavaScript. Do what thou wilt shall be the whole of the Law.

Have yet to view a case where code will be "broken" by ```nameof``` not being a JavaScript feature. "robustness", as already mentioned, is a subjective adjective that is not capable of being objectively evaluated as to code itself. That description is based on preference or choice.

In lieu of the proposal being specificed, use the posted code example of ```Object.keys()``` that "works".

provides a direct indication that the property value is required to be defined. Note that the example code posted thus far does not first check if ```options``` is passed at all, for which ```nameof``` will not provide any asssitance.

Usually try to meet requirement by means already available in FOSS browsers. Have no interest in TypeScript or using an IDE.

RE: Re: What do you think about a C# 6 like nameof() expression for

> `nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused why it'd be better to type `nameof foo` in code, rather than `'foo'` - if you change `foo` to `bar`, you have to change both of them anyways.

If you are using an editor that supports rename refactoring, its generally easier to rename the symbol `foo` and have all references (including `nameof foo`) be updated. You cannot safely automatically rename `'foo'` to `'bar'` since an
editor or language service cannot guarantee that by the string `'foo'` you meant “the text of the identifier `foo`”.

`nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused why it'd be better to type `nameof foo` in code, rather than `'foo'` - if you change `foo` to `bar`, you have to change both of them anyways.

Am neither for nor against the proposal. Do not entertain "like"s or "dislike"s in any field of endeavor. Am certainly not in a position to prohibit anything relevant JavaScript. Do what thou wilt shall be the whole of the Law.

Have yet to view a case where code will be "broken" by ```nameof``` not being a JavaScript feature. "robustness", as already mentioned, is a subjective adjective that is not capable of being objectively evaluated as to code itself. That description is based
on preference or choice.

In lieu of the proposal being specificed, use the posted code example of ```Object.keys()``` that "works".

provides a direct indication that the property value is required to be defined. Note that the example code posted thus far does not first check if ```options``` is passed at all, for which ```nameof``` will not provide any asssitance.

Usually try to meet requirement by means already available in FOSS browsers. Have no interest in TypeScript or using an IDE.

> `nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused why it'd be better to type `nameof foo` in code, rather than `'foo'` - if you change `foo` to `bar`, you have to change both of them anyways.

If you are using an editor that supports rename refactoring, its generally easier to rename the symbol `foo` and have all references (including `nameof foo`) be updated. You cannot safely automatically rename `'foo'` to `'bar'` since an
editor or language service cannot guarantee that by the string `'foo'` you meant “the text of the identifier `foo`”.

`nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused why it'd be better to type `nameof foo` in code, rather than `'foo'` - if you change `foo` to `bar`, you have to change both of them anyways.

Am neither for nor against the proposal. Do not entertain "like"s or "dislike"s in any field of endeavor. Am certainly not in a position to prohibit anything relevant JavaScript. Do what thou wilt shall be the whole of the Law.

Have yet to view a case where code will be "broken" by ```nameof``` not being a JavaScript feature. "robustness", as already mentioned, is a subjective adjective that is not capable of being objectively evaluated as to code itself. That description is based
on preference or choice.

In lieu of the proposal being specificed, use the posted code example of ```Object.keys()``` that "works".

provides a direct indication that the property value is required to be defined. Note that the example code posted thus far does not first check if ```options``` is passed at all, for which ```nameof``` will not provide any asssitance.

Usually try to meet requirement by means already available in FOSS browsers. Have no interest in TypeScript or using an IDE.

Re: Re: What do you think about a C# 6 like nameof() expression for

Fri, 14 jun 2019 - 18:29, Jordan Harband <[hidden email]> wrote:
>
> `nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused why it'd be better to type `nameof foo` in code, rather than `'foo'` - if you change `foo` to `bar`, you have to change both of them anyways.
>

Exactly, if you already have the name of the property beforehand in
design time why not write it as a string literal

Again, the only justifiable use case is refactoring tools, but even
today that can be arranged with static code analysis

You can safe guard a string literal to be a property of a type in
Typescript with a bit of handwork
``` ts
interface Options {
userName?: string;
}

// If you change the property in the interface without changing here, Typescript
// will raise a error informing that 'userName' is not a valid key of Options
const userNameKey: keyof Options = 'userName';