Fusyona / web3-core

GNU General Public License v3.0
0 stars 0 forks source link

Avoid "-" in mapping keys #43

Closed adrianhdez929 closed 2 months ago

adrianhdez929 commented 3 months ago

We should avoid using "-" character in any mapping key string in the future, since there is no valid character in TS/JS for variable naming, so when trying to import i.e: "taraxa-testnet", from networks.json file it throws error.

adrianhdez929 commented 3 months ago

I will add a fix for the networks.json file, but we should use camelCase or snake_case for mapping keys, this is the discussion open. I personally will go for camelCase in this one, but in that case (a lot of cases, this looks like a switch-case statement XD) we should choose between uppercase or lowercase for the key starting character

MakeMake23 commented 3 months ago

We should avoid using "-" character in any mapping key string in the future, since there is no valid character in TS/JS for variable naming, so when trying to import i.e: "taraxa-testnet", from networks.json file it throws error.

please, provide the error details and the code snippet

TheSnakeWitcher commented 3 months ago

These is because we don't access networks.json directly, instead we use a NetworkConfig, but anyway I don't see a reason to use a problematic style so for convenience maybe we should change it anyway. I agree with @adrianhdez929 about camelCase because typescript don't use snake_case to name anything

TheSnakeWitcher commented 3 months ago

We should avoid using "-" character in any mapping key string in the future, since there is no valid character in TS/JS for variable naming, so when trying to import i.e: "taraxa-testnet", from networks.json file it throws error.

please, provide the error details and the code snippet

I think that @adrianhdez929 refers to the fact that we can't

import { network } from "./networks.json" ;

If network is a network with a name containing - we won't be able to import it that way. When creating these i personally use - to be consistent with the filename style that we use before and because I personally use it like

import networks from "./networks.json" ;

networks["taraxa-testnet"] //  with autocompletion

I use it like that and I don't have any problem, but it is true that there is a potential incovenience with the - because it force to use networks like the 2 code snippet

adrianhdez929 commented 3 months ago

@MakeMake23 exactly what @TheSnakeWitcher said up there, there are ways to round the issue, because this is not widely adapted (at least not yet), but if we don't change this, we can only access an Object with keys kebab case as a dictionary and not directly call their members with the usual dot notation Object.member

adrianhdez929 commented 3 months ago

We should avoid using "-" character in any mapping key string in the future, since there is no valid character in TS/JS for variable naming, so when trying to import i.e: "taraxa-testnet", from networks.json file it throws error.

please, provide the error details and the code snippet

I think that @adrianhdez929 refers to the fact that we can't

import { network } from "./networks.json" ;

If network is a network with a name containing - we won't be able to import it that way. When creating these i personally use - to be consistent with the filename style that we use before and because I personally use it like

import networks from "./networks.json" ;

networks["taraxa-testnet"] //  with autocompletion

I use it like that and I don't have any problem, but it is true that there is a potential incovenience with the - because it force to use networks like the 2 code snippet

Actually what we can't do is:

import { taraxa-testnet } from "./networks.json";