Skip to content

Type 'null' is not assignable to type 'boolean | undefined' when using optional #26214

@alan-agius4

Description

@alan-agius4

TypeScript Version: 3.0.1

Search Terms:
null checks
Type 'null' is not assignable

Code

interface Foo {
    prop?: boolean;
}

const bar: Foo = {
    prop: null
};

I am not sure, if it's working as expected with TypeScript 3, but I didn't find any reference of this change.

With strictNullChecks, when having an optional property and one assigns a null it now emits an error.

I tried asking on gitter, but no one confirmed if it's a bug or not.

Expected behavior:
no error.

Actual behavior:

Type 'null' is not assignable to type 'boolean | undefined'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions