PatrickAlphaC / defi-stake-yield-brownie-freecode

53 stars 63 forks source link

Element implicitly has an 'any' type because expression of type 'ChainId' can't be used to index type #15

Closed AnneCh closed 2 years ago

AnneCh commented 2 years ago

Hi,

I'm working on the Main.tsx document, and I'm getting this error for both helperConfig and networkMapping :

for helperConfig: Element implicitly has an 'any' type because expression of type 'ChainId' can't be used to index type '{ "42": string; "4": string; "1337": string; "1": string; }'. Property '[ChainId.Ropsten]' does not exist on type '{ "42": string; "4": string; "1337": string; "1": string; }'.ts(7053)

for networkMapping: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ "42": { DappToken: string[]; TokenFarm: string[]; }; }'. No index signature with a parameter of type 'string' was found on type '{ "42": { DappToken: string[]; TokenFarm: string[]; }; }'.ts(7053)

Here is my Main.tsx:

// this will show what we have in our account, staked and not
import { useEthers} from "@usedapp/core"
import helperConfig from "../helper-config.json"
import networkMapping from "../chain-info/deployments/map.json"
import {constants} from "ethers"

export const Main = () => {
    // this needs to :
    // show token values from the wallet
    // Get the address of different tokens
    // get the balance of the users wallet
    // we need the information stored on the brownie-config.yaml file
    // with addresses for tokens and networks
    const { chainId, error } = useEthers()
    const networkName = chainId ? helperConfig[chainId] : "dev"
    // now we want to grab the address of the dappToken that we deployed on our kovan network 
    const dappTokenAddress = chainId ? networkMapping[String(chainId)]["DappToken"][0]: constants.AddressZero
    return (<div>Hello!</div>)
}

On top of that, when printing console.log(networkName) and console.log(chainId), I get this error message : supportedChain is deprecated, please pass networks instead For which I've tried the solutions proposed on this issue, unsuccessfully.

Any help greatly appreciated :)

PatrickAlphaC commented 2 years ago

What happens when you:

  1. rm -r node_modules
  2. rm yarn.lock
  3. Edit package.json to be:
    {
    "dependencies": {
    "@usedapp/core": "0.4.2"
    }
    }
  4. yarn

And then try it?

AnneCh commented 2 years ago

I see where my mistake was, I had two package.json, and only had modified one.

Now the network name and chainId show!

But I'm still having error messages on my Main.tsx. I've moved forward with creating the Wallet and displaying it on Main.tsx, and the same error message shows on brownieConfig["networks"][networkName]["weth_token] : constants.AddressZero :

Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{ development: { verify: boolean; }; rinkeby: { link_token: string; eth_usd_price_feed: string; dai_usd_price_feed: string; verify: boolean; }; kovan: { weth_token: string; fau_token: string; eth_usd_price_feed: string; dai_usd_price_feed: string; verify: boolean; }; }'.ts(7053)

for now it doesn't look like it's stopping anything from happening though... Should I just discard those warnings and move forward?

AnneCh commented 2 years ago

I've moved forward with the project and this error was replaced with another one that I'm currently working on fixing, so I'll close this issue

Meta-Sean commented 2 years ago

I had the same issue and this solved it, thanks!