Skip to content

[Suggestion] A way to mark .d.ts files that they are strictNullCheck compliant #14810

@mhevery

Description

@mhevery

A project often depends on other libraries which come with their own .d.ts files. For example:

Library: lib_a.d.ts

declare function foo(name: string): string;

When my project turns on strictNullChecks it is not clear to me if the lib_a.d.ts can be trusted. Because if it was compiled without strictNullChecks than my project should interpret it as:

Library: lib_a.d.ts

declare function foo(name: string|null|undefined): string|null|undefined;

but if it was compiled with strictNullChecks than the lib_a.d.ts should be trusted as is.

In real life there are often many library dependencies, and I would like to turn on strictNullChecks in my project before I have to wait that all of the third party libraries are ready.

Straw-man syntax would be:

Library: lib_a.d.ts

/// <compiler-options strictNullChecks: true>
declare function foo(name: string): string;

The TS compiler would than adjusted the types on the fly as it reads the libraries because it knows with what options they have been compiled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    SuggestionAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it adds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions