Skip to content

The TS4023-TS6133 Paradox (noUnusedLocals) #24287

@jeffijoe

Description

@jeffijoe

TypeScript Version: 2.8.3

Search Terms: TS6133 TS4023

Code

image

image

tsconfig.json

{
  "compilerOptions": {
    "strict": true,
    "strictNullChecks": true,
    "sourceMap": true,
    "declaration": true,
    "noUnusedLocals": true
  }
}

src/a.ts

import { createNamed } from "./b";

export const Value = createNamed();

src/b.ts

export interface Named {}

export function createNamed(): Named {
  return {};
}

Expected behavior:

Preferably that the compiler will know to add the import when emitting declarations (which I am aware is the root cause of the error in the first example).

If that's not possible, then the compiler should not trigger a warning for imported types that are used for declaration emission only.

Actual behavior:

The compiler reports an error when not importing types that get implicitly exported. When adding the import to satisfy that requirement, the compiler errors because of the noUnusedLocals option. Removing the unused local (the import) causes the first error, hence the reason I aptly labeled this a paradox.

Playground Link: This error requires the use of multiple files. Therefore I have attached screenshots and sources that can be used to reproduce the exact setup.

Related Issues: #5711, #9944

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions