Skip to content

Bug: No null checks in type parameters #17478

Closed
@mckauf

Description

@mckauf

TypeScript Version: 2.2.2

Code

interface List<T> {
    add(elem: T): void
}

function map(list: List<number>): List<number | null> {
    return list;
}

function foo(list: List<number>) {
    map(list).add(null);
}

Expected behavior:

Compiler should complain about line 6 (return list) when strictNullChecks is enabled, because add(elem: number): void has a different signature than add(elem: (number | null)): void.

Actual behavior:

This above code goes through the compiler, even though strictNullChecks, noImplicitAny et c. are all enabled. This results in that we can add null to a List<Number> in function foo and the compiler does not complain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions