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

Error identifying equality creating z.custom #30

Open
sonegobruno opened this issue Nov 16, 2023 · 4 comments
Open

Error identifying equality creating z.custom #30

sonegobruno opened this issue Nov 16, 2023 · 4 comments

Comments

@sonegobruno
Copy link

sonegobruno commented Nov 16, 2023

I encountered a problem identifying equality between types generated by z.custom on an object

General file
Captura de tela de 2023-11-16 09-19-04

Schema type inferred
Captura de tela de 2023-11-16 09-24-56

Type created
Captura de tela de 2023-11-16 09-24-59

It can be seen that when the schema assert is performed directly it passes without problems. However, when asserting within an object it presents an error even though it has the same typing.

I also noticed that when determining the attribute as optional the error disappears.

@garronej
Copy link
Owner

garronej commented Nov 16, 2023

Hello @sonegobruno,

Yeah sorry, I have to work on the Equals type, it sometimes gives fals negative, it's still better that false equality.

The workaround I iplement when the Equal type chokes is:

{
  type Expected = Shema;
  type Got = z.infer<typeof statusShema>;

  assert<Expected extends Got ? true : false>();
  assert<Got extends Expected ? true : false>();
}

As long as your types does not involves function this is bullet poof. If your types involves function it might, in certain edge cases, yield false positive (deeming equals types that are not).

@garronej
Copy link
Owner

Also, quick tip, I encourage you to use anonymous scope {} for testing equality of your types. It makes the core easyer to reason about and enable to reuse the same generic names multiple times in a single file.

@sonegobruno
Copy link
Author

Olá@sonegobruno,

Sim, desculpe, tenho que trabalhar no Equalstipo, às vezes dá falso negativo, ainda é melhor aquela falsa igualdade.

A solução alternativa que implemento quando o tipo Equal é bloqueado é:

{
  type Expected = Shema;
  type Got = z.infer<typeof statusShema>;

  assert<Expected extends Got ? true : false>();
  assert<Got extends Expected ? true : false>();
}

Contanto que seus tipos não envolvam função, isso é um bullet poof. Se seus tipos envolvem função, ele pode, em certos casos extremos, gerar falsos positivos (considerando tipos iguais que não são).

Thanks this worked for me 👍

@garronej garronej reopened this Nov 16, 2023
@garronej
Copy link
Owner

Glad the workaround does it for you!

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