In my Typescript Brainfuck interpreter (or executer), I am looking to implement a validation process for the input. The goal is to create a type that only allows specific characters, similar to this:
type BrainfuckCode = /* Custom type that permits only <>+-.,[] */
const input1: BrainfuckCode = "+++++++>"
// No error should occur in this case
const input2: BrainfuckCode = "+++++++>INVALID CHARACTERS"
// An error should be triggered here
I'm trying to find a solution without hardcoding the string length. Here's what I have so far:
type BrainfuckCode = "<" | ">" | "+" | "-" | "." | "," | "[" | "]"