# JS Variable$Types vs. Variable : Types

**URL:** <https://es.discourse.group/t/js-variable-types-vs-variable-types/2105>\
**Category:** 💡 Ideas\
**Created:** [August 9, 2024, 8:35pm UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105 "2024-08-09T20:35:35Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![KooIaIa](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kooiaia/32/2178_2.png) [@KooIaIa](https://es.discourse.group/u/KooIaIa)\
**Post date:** [August 11, 2024, 11:29pm UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/21 "2024-08-11T23:29:38Z")

</div>

As a delegate, I take your opinion seriously. Please try and see how important this could be. I promise I am reading what you say and taking your opinion into account.

var banana = {}

See this variable? Can you tell what type it is?

---

<div class="post-metadata">

**Author:** ![bergus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/bergus/32/152_2.png) [@bergus](https://es.discourse.group/u/bergus)\
**Post date:** [August 12, 2024, 12:03am UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/22 "2024-08-12T00:03:57Z")

</div>

> [@KooIaIa](#):
>
> It isn't adding semantics if it isn't used programmatically. Again, I am not saying variable names should suddenly be usable programmatically.

Then what exactly _are_ you suggesting?

---

<div class="post-metadata">

**Author:** ![KooIaIa](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kooiaia/32/2178_2.png) [@KooIaIa](https://es.discourse.group/u/KooIaIa)\
**Post date:** [August 12, 2024, 12:46am UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/23 "2024-08-12T00:46:35Z")

</div>

A social convention with TS that causes zero changes to JS which would allow Types to be helpful meta data in variable names for humans.

I'm happy to humor discussing any issues this may cause. If you can give a real world example please do.

Thank you for the question because this is a super confusing subject. Both comments and names can carry completely optional meaning without breaking any JavaScript programs or backwards compatibility.

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [August 12, 2024, 12:59am UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/24 "2024-08-12T00:59:40Z")

</div>

A social convention isn’t something that TC39 would decide. If you want to use and encourage such a thing, go for it!

---

<div class="post-metadata">

**Author:** ![KooIaIa](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kooiaia/32/2178_2.png) [@KooIaIa](https://es.discourse.group/u/KooIaIa)\
**Post date:** [August 12, 2024, 1:00am UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/25 "2024-08-12T01:00:22Z")

</div>

Your being horribly unfair to my language choices. Here tear me apart:

TC39 Proposal:  
$ - is a new fully optional meta identifier so typescript code can compile to javascript code with types

shoot me. whats the problem? im not suggesting to then make js into ts or change anything.

---

<div class="post-metadata">

**Author:** ![bergus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/bergus/32/152_2.png) [@bergus](https://es.discourse.group/u/bergus)\
**Post date:** [August 12, 2024, 1:08am UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/26 "2024-08-12T01:08:18Z")

</div>

If you only want a social convention, and not change the ECMAScript language specification, this is probably the wrong discussion forum. But sure, pitch your idea to the TypeScript authors! It would be them who would have to change their compiler code.

Though imo, name mangling is hard to do correct (without introducing conflicts) and would probably break some code (that relies on identifier names, and in particular property names); so I suspect this proposal would be shot down. Personally, I don't have a large need to read transpiled TypeScript code anyway, I can either read the source code or there's a source map accompanying the JS code.

---

<div class="post-metadata">

**Author:** ![KooIaIa](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kooiaia/32/2178_2.png) [@KooIaIa](https://es.discourse.group/u/KooIaIa)\
**Post date:** [August 12, 2024, 1:10am UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/27 "2024-08-12T01:10:08Z")

</div>

Please give me example code that breaks. I need real world problems!! Your example would require major negligence wouldn't it?!

Is the error once someone does Object Stringify?

For context bergus, there is a Typed Comment proposal in TC39. This is absolutely the place for this discussion - so is TS.

---

<div class="post-metadata">

**Author:** ![KooIaIa](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kooiaia/32/2178_2.png) [@KooIaIa](https://es.discourse.group/u/KooIaIa)\
**Post date:** [August 12, 2024, 1:13am UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/28 "2024-08-12T01:13:02Z")

</div>

A standard is a social convention. OMG. I promise I am not nuts. I was only trying to say I didn't want to change the JS engine itself. This only requires a actual code change to TS.

Whats the point for me to talk to TS people about types compiling into JS when you all tell me No without any example on hypothetical technical grounds?

---

<div class="post-metadata">

**Author:** ![KooIaIa](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kooiaia/32/2178_2.png) [@KooIaIa](https://es.discourse.group/u/KooIaIa)\
**Post date:** [August 12, 2024, 1:28am UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/29 "2024-08-12T01:28:15Z")

</div>

This whole thread feels like a misunderstanding :( I am not good at social convention.

I will try and talk to the Type Comment people about Type Names but I am dreading it already.

---

<div class="post-metadata">

**Author:** ![KooIaIa](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kooiaia/32/2178_2.png) [@KooIaIa](https://es.discourse.group/u/KooIaIa)\
**Post date:** [August 12, 2024, 1:55am UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/30 "2024-08-12T01:55:56Z")

</div>

> A social convention isn’t something that TC39 would decide.

This is completely false your saying it backwards. The entire point of a Standard is to create social convention and the entire point of an Identifier is to be valid.

Who here thinks TS doesn't depend on the TC39 standard? The entire point of this thread is to discuss a standard between JS and TS.

This is gas lighting isn't it? My proposal is 1 line of code.

---

<div class="post-metadata">

**Author:** ![bergus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/bergus/32/152_2.png) [@bergus](https://es.discourse.group/u/bergus)\
**Post date:** [August 12, 2024, 8:48pm UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/31 "2024-08-12T20:48:07Z")

</div>

> [@KooIaIa](#):
>
> Please give me example code that breaks.

This is working TypeScript:

```ts
class Example {
 constructor(public property: string) {}
}
const instance = new Example("value");
const value = instance[`${"prop"}${"erty"}`];
console.log(value);

```

Your suggestion appears to be to transpile this to the following JavaScript:

```javascript
class Example$typeofExample {
  property$string;
  constructor(property$string) {
    this.property$string = property$string;
  }
}
const instance$Example = new Example$typeofExample("value");
const value$string = instance$Example[`${"prop"}${"erty"}`];
console$Console.log(value$string);

```

This doesn't work any more due to at least two problems.

> [@KooIaIa](#):
>
> A standard is a social convention.

The ECMAScript standard is a technical specification, describing in utmost detail how to parse and interpret code. It has nothing to do with social conventions.

Sure, there's other coding standards like styleguides that you can choose to follow or not (or create and popularise your own), but those are not discussed in this forum.

---

<div class="post-metadata">

**Author:** ![KooIaIa](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kooiaia/32/2178_2.png) [@KooIaIa](https://es.discourse.group/u/KooIaIa)\
**Post date:** [August 12, 2024, 9:24pm UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/32 "2024-08-12T21:24:40Z")

</div>

Thank you for the detailed example. Is the solution there simply to not apply this rule to properties in classes like that? It's not super clear and your code is doing a lot of weird stuff. It is a great sample of how much we use Names as Types already.

I recommend not "Typing Everything" just for the sake of it like you have shown. It feels like you transpiled the code in the worst way you possibly could when the goal is to find the best way.

Pretend this literally only applies to variables. If your reading the variable name your doing it for a reason so explain the reasoning.

I was thinking about this only for simple variable types like my examples so your perspective is greatly appreciated.

> social convention semantics

This kind of detail you just brought up would be great in a standard technical specification on how to safely denote TS types in JS. I am working on making a proposal.

A TC39 JS Typing style guide for TypeScript honestly sounds like a great idea too but as you say we better not use unallowed idea framing.

---

<div class="post-metadata">

**Author:** ![KooIaIa](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kooiaia/32/2178_2.png) [@KooIaIa](https://es.discourse.group/u/KooIaIa)\
**Post date:** [August 12, 2024, 10:09pm UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/33 "2024-08-12T22:09:03Z")

</div>

> [@bergus](#):
>
> `${"prop"}${"erty"}`

Is this the error here? This extreme unnatural form of negligence is why this cannot work?

None of these issues appear in JS obviously so it is important to figure out what TS compiler problems I really need to worry about. Ultimately nothing is requiring all old code and new code to do anything.

Pretend 2 things:

1. A TC39 Standard Recommendation for storing Types in names with an Identifier as completely optional human readable helpful variable describing name data. (similar to Typed Comments)
2. Completely optional build tooling (a TS build option) to compile into the new TC39 format.

This way - no one doing TS Metaprogramming gets suddenly surprised and nothing breaks. The final work then is me implementing the change into TS. Is this idea crazy? Yes. Is it actually simple? Yes I think if we try to make it be!

---

<div class="post-metadata">

**Author:** ![bergus](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/bergus/32/152_2.png) [@bergus](https://es.discourse.group/u/bergus)\
**Post date:** [August 12, 2024, 11:10pm UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/34 "2024-08-12T23:10:44Z")

</div>

> [@KooIaIa](#):
>
> Is the solution there simply to not apply this rule to properties in classes like that?

And properties in objects. And global variables. And exports. And parameter names. And probably a lot of other things that code in the wild depends on.

> [@KooIaIa](#):
>
> Your code is a great sample of how much we use Names as Types already.

The names in my example snippet are absolutely meaningless.

> [@KooIaIa](#):
>
> Is this the error here? This extreme unnatural form of negligence is why this cannot work?

No, that's just a very short example of property access with a non-trivial expression that TypeScript still accepts. You can construct your own example with some more dynamic expressions and less weird syntax.

> [@KooIaIa](#):
>
> Pretend 2 things

You don't actually need the first thing - I mean you may need a recommendation, but it doesn't have to be an ECMA standard. You can just start building the _completely optional build tooling_. If you can convince enough people that using this build option is beneficial for them, and it becomes hugely popular, so popular that alternative implementations of the same idea pop up that do things slightly differently, _that_ is when you may need a standard to guarantee interoperability. Although I still fail to see what the possible interoperability issues would be if the names are not supposed to be used programmatically anywhere.

---

<div class="post-metadata">

**Author:** ![KooIaIa](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kooiaia/32/2178_2.png) [@KooIaIa](https://es.discourse.group/u/KooIaIa)\
**Post date:** [August 12, 2024, 11:12pm UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/35 "2024-08-12T23:12:25Z")

</div>

Thanks for the recommendation. If Typed Comments are a valid idea for TC39 I believe Typed Names are too. My Stage 1 proposal could be to ask if JS indeed does need a new Valid Identifier for Types or not.

It frustrates me that in order to make a proposal valid in your eyes I must add new syntax like Typed Comments. However, it should be considered since $ is already a valid identifier. The TC39 proposal should ask if we need new syntax for Types in JS or not? If we do want Types in JS, should it be new Name Type syntax or new Comment Type syntax.

I will do my best to figure out how to frame my Proposal correctly.

---

<div class="post-metadata">

**Author:** ![KooIaIa](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kooiaia/32/2178_2.png) [@KooIaIa](https://es.discourse.group/u/KooIaIa)\
**Post date:** [August 12, 2024, 11:31pm UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/36 "2024-08-12T23:31:55Z")

</div>

Does anyone have any ideas for a good new identifier to add to JS to denote a Type in a variable name?

> [@ljharb](#):
>
> already valid in identifiers

Right now the valid only options are:

\_  
A-z  
0-9  
$...

I wonder what TC39 would consider a good new Identifier to add here for Types. I will brainstorm this.

Lets please restart on fresh footing now and take a bunch of steps back. Maybe we can come up with an even better letter than $ to propose.

---

<div class="post-metadata">

**Author:** ![KooIaIa](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kooiaia/32/2178_2.png) [@KooIaIa](https://es.discourse.group/u/KooIaIa)\
**Post date:** [August 13, 2024, 12:49am UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/37 "2024-08-13T00:49:08Z")

</div>

Type Identifier to discuss: "."

notes.txt  
program.exe

See the name and type? A real life Type Identifier!

We obviously can't use "." as a new Variable Type identifier but see how beautiful and seamless it is since we are used to seeing it our whole lives?

We can propose a new valid identifier even better than this for JS Variable Types. $ is a great backup plan but its obvious how important Types are to programming names and a new valid identifier could be incredible for JS and make a great new standard. The best thing about a new official TC39 JS type identifier is it would essentially add JS type identifiers to JSON too. I think other JS programmers could get excited about this too. The idea isn't that spooky or complicated I promise. Don't let overly complex TS variable name metaprogramming scare you away from a perfectly valid simple JS standard for Types. It's more important to JS than it is to TS which is why TC39 is the place to discuss it. I'm a JS dev and want a standard to use Types in my code and there is nothing wrong with such a proposal.

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [August 13, 2024, 3:04am UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/38 "2024-08-13T03:04:57Z")

</div>

How would type arguments work:

```javascript
let m: Map<string, Set<string>>;

```

becomes `m$...` ?

---

<div class="post-metadata">

**Author:** ![KooIaIa](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kooiaia/32/2178_2.png) [@KooIaIa](https://es.discourse.group/u/KooIaIa)\
**Post date:** [August 13, 2024, 3:25am UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/39 "2024-08-13T03:25:33Z")

</div>

m$Map - which makes sense im guessing its the reason why you named it "m".

---

<div class="post-metadata">

**Author:** ![lightmare](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/lightmare/32/843_2.png) [@lightmare](https://es.discourse.group/u/lightmare)\
**Post date:** [August 13, 2024, 7:25am UTC](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105/40 "2024-08-13T07:25:54Z")

</div>

I think you're in the wrong forum. IIUC, you want tsc to emit type information attached to local variable identifiers. Then head to [Issues · microsoft/TypeScript · GitHub](https://github.com/microsoft/TypeScript/issues). However, I suggest you first peruse [TypeScript Design Goals · microsoft/TypeScript Wiki · GitHub](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals), particularly goal 9 and non-goal 5. It kinda sounds like you're going against those.

[Previous page](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105.md?page=1)

[Next page](https://es.discourse.group/t/js-variable-types-vs-variable-types/2105.md?page=3)
