superstruct
superstruct copied to clipboard
optional on unknown is still required, probably a bug?
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
It seems like this is a limitation in TypeScript itself?
type A = unknown;
type B = unknown | undefined;
Both are inferred as unknown
by TypeScript.