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

optional on unknown is still required, probably a bug? #856

Open
teneon opened this issue Jul 6, 2021 · 1 comment
Open

optional on unknown is still required, probably a bug? #856

teneon opened this issue Jul 6, 2021 · 1 comment
Labels
bug ♥ help please Issues that we'd love help solving

Comments

@teneon
Copy link

teneon commented Jul 6, 2021

Hi there,

there seems to be a bug when you try to make unknown() optional. Let's take a look at the simple example:

  const TestStruct = object({
    foo: optional(string()),
    baz: optional(unknown())
  });

  type Type = Infer<typeof TestStruct>;

Both foo and baz should be optional, but if you add the snippet to VSCode, hover mouse over Type, you can see that "foo" is optional, but "baz" is required.

If we compare this to the standard TS type:

  type Type = {
    baz?: unknown
  }

If you hover mouse over "Type", you can see that "baz" is actually optional, which is also expected behaviour.
It looks like a bug to me? Please let me know what u guys think?

Amazing library btw! ;)

best regards,
Neon

@ianstormtaylor ianstormtaylor added bug ♥ help please Issues that we'd love help solving labels Sep 8, 2021
@Mrtenz
Copy link
Contributor

Mrtenz commented Sep 26, 2022

It seems like this is a limitation in TypeScript itself?

type A = unknown;
type B = unknown | undefined;

Both are inferred as unknown by TypeScript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ♥ help please Issues that we'd love help solving
Projects
None yet
Development

No branches or pull requests

3 participants