Skip to content

Invalid function assignment is not detected #18337

Closed
@VictorNicollet

Description

@VictorNicollet

TypeScript Version: 2.5.0

Code

const a: (d: string) => number = (d) => d.length;
const b: (d?: string) => number = a;
b();

Expected behavior:
When compiled with --strict, the assignment of b should cause a type error along the lines of:

string | undefined is not assignable to type string.

Actual behavior:
The code compiles with --strict, then throws an exception at runtime on the expression d.length.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions