Skip to content

Casting generics ignores --strictNullCheck #13513

Closed
@0xShammah

Description

@0xShammah

TypeScript Version: 2.1.5

Code
Minimal example that compiles just fine:

let x: Promise<string | undefined> = Promise.resolve(undefined);
let y: Promise<string> = x;

Small usage example in which I encountered the bug:

interface ITest {
    test(): Promise<string>;
}

class Test implements ITest{
    test(): Promise<string | undefined> {
        return Promise.resolve(undefined);
    }
}

var test = new Test();
test.test().then(console.log);

Expected behavior:
A compile error: the type Promise<string | undefined> does not match the type Promise<string>. I should not be able to cast undefined to string.

Actual behavior:
No errors.

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