Skip to content

Type 'unknown' should no be assignable to type '{}' #36485

Closed
@feeddageek

Description

@feeddageek

Typescript no longer preventing assignation of unknown to {} without strictNullChecks

TypeScript Version: from 3.5.3 to 3.7.5
Work as expect from 3.0.3 to 3.4.5

Search Terms: unknown assignable {} empty type

Code

    let a: unknown;
    const b: {} = a;
    const c: object = a;

Expected behavior:

    let a: unknown;
    const b: {} = a;// Type 'unknown' is not assignable to type '{}'.
    const c: object = a;// Type 'unknown' is not assignable to type 'object'

Actual behavior:

    let a: unknown;
    const b: {} = a;// No error for this line
    const c: object = a;// Type 'unknown' is not assignable to type 'object'

Playground Link:
3.3.3 strictNullChecks=true Error as expected
3.3.3 strictNullChecks=false Error as expected
3.7.5 strictNullChecks=true Error as expected
3.7.5 strictNullChecks=false Missing error
Related Issues:
#26796

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