Element implicitly has an 'any' type because expression of type 'string' can't be used to index type object react typescript code example
Example: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type { }. No index signature with a parameter of type 'string' was found on type '{ develop: string; staging: string; production: string; }'.ts(7053)
const DNATranscriber = {
G: 'C',
C: 'G',
T: 'A',
A: 'U'
};
export default class Transcriptor {
toRna(dna: string) {
const codons = [...dna];
if (!isValidSequence(codons)) {
throw Error('invalid sequence');
}
const transcribedRNA = codons.map(codon => DNATranscriber[codon]);
return transcribedRNA;
}
}
function isValidSequence(values: string[]): values is Array<keyof typeof DNATranscriber> {
return values.every(isValidCodon);
}
function isValidCodon(value: string): value is keyof typeof DNATranscriber {
return value in DNATranscriber;
}