[TypeScript] Distinguishing between types of Strings in TypeScript
Posted Answer1215
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[TypeScript] Distinguishing between types of Strings in TypeScript相关的知识,希望对你有一定的参考价值。
In javascript, many libraries use string arguments to change behavior. In this lesson we learn how Typescript catches string related errors at compile time by assigning a string literal as a type.
type whiteList = "DOG" | "CAT" | "BIRD"; function allowToTake(num: number, animal: whiteList): string{ return `You can bring ${num} ${animal}`; }
以上是关于[TypeScript] Distinguishing between types of Strings in TypeScript的主要内容,如果未能解决你的问题,请参考以下文章