Skip to content

--strictNullChecks does not gaurd against optional arguments assignment #9450

Closed
@Raynos

Description

@Raynos

TypeScript Version: Version 1.9.0-dev.20160610-1.0

Code

var foo: (baz?: string) => string;

foo = function watwat(baz: string): string {
    return baz.toString();
};

foo(undefined);

Expected behavior:

Expected "Cannot call foo() with undefined"

Actual behavior:

No errors output.

When running node wat.js we get an expected uncaught exception

/home/raynos/projects/http-hash-server/lib/wat.js:3
    return baz.toString();
               ^
TypeError: Cannot call method 'toString' of undefined

My actual production use case is more complicated and involves assigning interfaces into a generic container class where the generic container class has an interface with optional arguments and the instance of the class that as#to the container has methods with non-optional arguments.

I expected that the structural equality checker would fail for optional arguments vs non-optional arguments when --strictNullChecks is enabled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions