-
Notifications
You must be signed in to change notification settings - Fork 35
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 property set to undefined fails validation #25
Comments
Hi @blombern Yes this is expected behavior. I think it's a bit quirky the way TypeScript deals with optional properties and Also, interface Foo {
foo: string | undefined;
}
const x: Foo = {}; // <--- error: missing property "foo" I think keeping the distinction allows for more precise definitions of the types, either some property is always there and possibly undefined, or some property can be missing. |
@woutervh- I want to re-raise this question still since the behavior of TS and behavior of typescript-is is different here. An example:
At the same time, the following code is perfectly fine (and is by design) in TS:
Above, you mention that I.e. in TS, I think typescript-is'es goal is to be as close to TS native behavior as possible (that's the power of this library), and also it's mostly used for JSON-deserialized values which by definition cannot have
So in practice, even if typescript-is allows people assign undefined to ?-properties, this will not break compatibility much. |
Is this expected behavior? I thought
a?: string
anda: string | undefined
were equivalent in TypeScript.The text was updated successfully, but these errors were encountered: