Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested props fail type check #99

Open
nikksan opened this issue Apr 29, 2021 · 1 comment
Open

Nested props fail type check #99

nikksan opened this issue Apr 29, 2021 · 1 comment

Comments

@nikksan
Copy link

nikksan commented Apr 29, 2021

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.

@samchon
Copy link
Contributor

samchon commented Oct 10, 2022

Use this, then no problem on such union type

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants