Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ "31337": string[]; }' #3
Answered
by
PatrickAlphaC
PatrickAlphaC
asked this question in
Q&A
-
I'm working on the const { chainId: chainIdHex, isWeb3Enabled } = useMoralis()
const chainId = parseInt(chainIdHex!).toString()
const raffleAddress = chainId in contractAddresses ? contractAddresses[chainId] : null My VSCode is telling me:
How do I fix this? |
Beta Was this translation helpful? Give feedback.
Answered by
PatrickAlphaC
Apr 14, 2022
Replies: 1 comment
-
You need to create an interface for the code! Typescript will be confused by the typings otherwise: interface contractAddressesInterface {
[key: string]: string[]
}
// some code here
const addresses: contractAddressesInterface = contractAddresses
const { chainId: chainIdHex, isWeb3Enabled } = useMoralis()
const chainId: string = parseInt(chainIdHex!).toString()
const raffleAddress = chainId in addresses ? addresses[chainId][0] : null |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
PatrickAlphaC
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to create an interface for the code! Typescript will be confused by the typings otherwise: