8000 Problem with optional properties · Issue #45 · woutervh-/typescript-is · GitHub
[go: up one dir, main page]

Skip to content
Problem with optional properties #45
@mvcbox

Description

@mvcbox

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0