typescript-is icon indicating copy to clipboard operation
typescript-is copied to clipboard

Nested props fail type check

Open nikksan opened this issue 3 years ago • 1 comments

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.

nikksan avatar Apr 29 '21 14:04 nikksan

Use this, then no problem on such union type

https://github.com/samchon/typescript-json#runtime-validators

samchon avatar Oct 10 '22 15:10 samchon