typescript-is
typescript-is copied to clipboard
Nested props fail type check
Types created using type functions with nested props don't work correctly.
type CustomType<Color> = {
bar: {
color: Color,
},
}
type MyType1 = CustomType<'red'>;
type MyType2 = CustomType<'blue'>;
type MyType = MyType1 | MyType2;
console.log(
is<MyType>({
bar: {
color: 'red',
}
}),
is<MyType>({
bar: {
color: 'blue',
}
}),
);
^ outputs true, false
. Just for comparasion, if the color
was not nested, the same example works.
Use this, then no problem on such union type
https://github.com/samchon/typescript-json#runtime-validators