1
typeScriptにリストされた値の1つだけを許可するタイプがありますか?私が欲しいものtypeScriptにリストされた値の1つのみを許可するタイプ
:
typethatiwant Animals = ['cat', 'dog'];
let myAnimal: Animals = 'cat'; // good
myAnimal = 'dog'; // good
myAnimal = 'hamster'; // error because 'hamster' not 'cat' or 'dog'
でそれを参照してください。 [文字列リテラル](https:// www .typescriptlang.org/docs/handbook/advanced-types.html)。 – Alex
@Alexはい!回答が更新されました –
ありがとうございました!これは私のために働く。 – ruvi