Skip to content

Optional parameters should reject undefined parameter values #10014

Closed
@falsandtru

Description

@falsandtru

For example, a following signature of function f should be defined like function g with strictNullChecks option.

TypeScript Version: master

Code

function f(a?: number) {
}
f();
f(0);
f(undefined);

function g()
function g(a: number)
function g(a?: number) {
}
g();
g(0);
g(undefined);

Expected behavior:

$ node built/local/tsc.js --strictNullChecks index.ts
index.ts(5,3): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.
index.ts(13,3): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.

Actual behavior:

$ node built/local/tsc.js --strictNullChecks index.ts
index.ts(13,3): error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'number'.

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