TypeScriptでユーザー定義型の判定
code:ts
// const assertion
const factorType = "aaa", "bbb" as const;
// factorTypeの要素の型 -> "" | "aaa" | "bbb"
type FactorType = typeof factorTypenumber; function isFactorType(value: any): value is FactorType {
return factorType.includes(value);
}