0
const abc = (str: string) => str

How do restrict string to specified value like 'a' and 'b' only?

I know it can be an enum but I want to make it one liner

alice_morgan
  • 151
  • 7
  • 2
    Why do you want to make it a one liner? Code clarity is more important than concision. Just use enum. – Shrey Joshi Jun 02 '21 at 02:13
  • Does this answer your question? [How to require a specific string in TypeScript interface](https://stackoverflow.com/questions/26855423/how-to-require-a-specific-string-in-typescript-interface) – Joe Sep 13 '21 at 07:38

1 Answers1

0

if u want to make a string like that you can do

const abc:'a'|'b' = 'a'
Amir Saadallah
  • 668
  • 1
  • 8
  • 19