Skip to content

Turning on strictNullChecks also errors on libraries that haven't turned it on #12615

Closed
@Vinnl

Description

@Vinnl

TypeScript Version: 2.0.10

When I've turned on strictNullChecks for my project, I get errors on TypeScript projects a depend on that haven't turned that on.

For example, RxJS 5 has not enabled strictNullChecks:

Code

// fromEvent expects the first parameter to be of type EventTargetLike - but, since it's compiled without strictNullChecks, null is valid as well.
Observable.fromEvent(document.getElementById('button'), 'click')

Expected behavior:
The above code to just compile.

Actual behavior:
A compilation error:

    Error TS2345: Argument of type 'HTMLElement | null' is not assignable to parameter of type 'EventTargetLike'.
    Type 'null' is not assignable to type 'EventTargetLike'.

I'm not sure what the best solution is. I don't think they're shipping their own tsconfig, as far as I can see. In any case, that could be problematic as well, if they're using a different version of TypeScript - I guess TypeScript should remain forwards compatible as well.

Perhaps the generated .d.ts files could, during compilation, be modified to add | null to every type to at least ensure compatibility with dependent projects that have enabled strict null checks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions