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

Problem with optional properties #45

Closed
mvcbox opened this issue Dec 26, 2019 · 3 comments
Closed

Problem with optional properties #45

mvcbox opened this issue Dec 26, 2019 · 3 comments

Comments

@mvcbox
Copy link

mvcbox commented Dec 26, 2019

Hello!
I noticed some peculiarity when working with optional properties.
For example:

interface SomeInterface {
    someOptionalProperty?: string;
}

const value: SomeInterface = { someOptionalProperty: undefined };

This code is quite valid and can be compiled without any problems.

Example with assertType:
For example:

interface SomeInterface {
    someOptionalProperty?: string;
}

const value: SomeInterface = assertType<SomeInterface>({ someOptionalProperty: undefined });

In this case, I will get the error:

TypeGuardError: validation failed at $.someOptionalProperty: expected a string
@mvcbox
Copy link
Author

mvcbox commented Dec 26, 2019

@woutervh- Can you check it please?

@woutervh-
Copy link
Owner

hi @mvcbox

This is by design. Please see #25 for more info ;)

@mvcbox
Copy link
Author

mvcbox commented Dec 30, 2019

@woutervh- , okay(
Thank for answer

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