I get a compilation error:
Element implicitly has an 'any' type because expression of type 'number' can't be used to index type '{ G: string; C: string; T: string; A: string; }'.
No index signature with a parameter of type 'number' was found on type '{ G: string; C: string; T: string; A: string; }'.(7053)
on Transcriptor.DNA_TO_RNA_NUCLEOTIDES[dnsNucleotide]
in the following code:
class Transcriptor {
static readonly DNA_TO_RNA_NUCLEOTIDES = { 'G': 'C', 'C': 'G', 'T': 'A', 'A': 'U' }
toRna(dnaStrand: string) {
let rnaStrand: string = ""
const dnaAsArray: string[] = Array.from(dnaStrand)
for (const dnsNucleotide in dnaAsArray) {
const rnaNucleotide: string = Transcriptor.DNA_TO_RNA_NUCLEOTIDES[dnsNucleotide]
rnaStrand += rnaNucleotide
}
return rnaStrand
}
}
export default Transcriptor
I would understand that this happened if dnsNucleotide
could be any
, but in this case it's a string
, so where is number
being inferred from?
I know I can fix it with static readonly DNA_TO_RNA_NUCLEOTIDES: { [key: string]: string} = {...}