Skip to content

Incremental builds ignore missing ambient declarations #36728

Closed
@fgallardograzio

Description

@fgallardograzio

TypeScript Version: 3.8.0-dev.20200208

Search Terms: incremental build ambient declarations declare global dts

Code

// globals.d.ts
declare namespace Config {
  const value: string;
}
// index.ts
console.log(Config.value);
// tsconfig.json
{
  "compilerOptions": {
    "incremental": true
  }
}

Steps to reproduce:

  • Run tsc. The project should be built successfully.
  • Remove the contents of globals.d.ts or delete the file itself. (vscode immediately reports the "Cannot find name 'Config'." error in index.ts).
  • Run tsc again. The build process still completes successfully.
  • Run tsc --incremental false. Now it fails correctly.

Expected behavior:
The removal of an ambient declaration should be caught by TS when using --incremental or --build and the proper error should be reported.

Actual behavior:
When a complete ambient type declaration is removed, related types don't seem to be re-checked.

On the other hand, changing an ambient declaration works as expected.
If, e.g., the value constant is removed from the namespace declaration, the proper error is thrown.

// globals.d.ts
declare namespace Config {
//   const value: string;
}

Please note that this also affects project references' --builds.

Playground Link:
Not needed.

Related Issues:
Not an issue, but maybe #32849 is related?

Thanks

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: --incrementalThe issue relates to incremental compilationFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions