Skip to content

Variable with advanced type with optional property can be assigned simple type value #17843

Closed
@hoegge

Description

@hoegge

TypeScript Version: TSLint 2.4.0 in VSCode and www.typescriplang.org playground today (2017-08-16)

Code

let a: { property?: string } = 1234; // why is this allowed?

Expected behavior:
It should not be possible to assign a number to a variable a of type { property?: string } or ... { property?: string | undefined; } if strict-null-check is turned on.

Actual behavior:
a is assigned the value 1234
If the type's property is not optional, it behaves as expected, i.e. type { property: string }.

Activity

DanielRosenwasser

DanielRosenwasser commented on Aug 16, 2017

@DanielRosenwasser
Member

Duplicate of #16333. Should be fixed in TypeScript 2.4.2.

locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @DanielRosenwasser@hoegge

        Issue actions

          Variable with advanced type with optional property can be assigned simple type value · Issue #17843 · microsoft/TypeScript