Home > Back-end >  TypeScript: a string of characters of <type>
TypeScript: a string of characters of <type>

Time:06-23

Maybe I'm losing it.

I've got a list of possible nucleotides and a corresponding type:

const DNA = ['G', 'C', 'T', 'A'] as const;

type DNA = typeof DNA[number];

Now, a DNA strand could be a string of any of the characters (GCTA), in any combination, of any length. What's important here, is that each individual character is of type DNA.

If I split('') this strand, I want to get an array of characters, each of these characters of type DNA, e.g,

const strand: ??? = "GACATAGACGCGTTAG";
const DNAstring: DNA[] = strand.split('');

How do I type the strand in this case?

  • Related