Skip to content

'void' parameters treated as optional only for calls, but not for assignability. #40227

Closed
@rbuckton

Description

@rbuckton

TypeScript Version: 4.0.2

Search Terms: signature void parameter optional assignability

Code

declare function f(a: number, b?: void): void;
declare function g(a: number, b: void): void;
f(1); // ok
g(1); // ok

let ff: (a: number) => void = f; // ok
let gg: (a: number) => void = g; // error

Expected behavior:

g should be assignable to gg since we treat void parameters as optional.

Actual behavior:

g is not assignable to gg.

Playground Link: link

Related Issues: #39817, #29131

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions