Skip to content

Generating Type Definitions from Javascript is blocked by requiring private name #37832

Closed
@nbbeeken

Description

@nbbeeken

TypeScript Version: 3.9.0-dev.20200407

Search Terms:

  • TS9006
  • Declaration emit for this file requires using private name
  • Explicit type annotation
  • Unblock declaration emit.

Code

// thing.js // maybe something from deep in my library
'use strict';
class Thing {}
module.exports = { Thing };
// index.js
"use strict";
const Thing = require("./thing").Thing;
module.exports = { Thing }; // re-export to the world

tsconfig.json:

{
  "compilerOptions": {
    "allowJs": true,
    "checkJs": true,
    "declaration": true,
    "emitDeclarationOnly": true,
    "declarationDir": "types",
    "strict": false,
    "target": "ES2018",
    "module": "commonJS",
    "moduleResolution": "node",
    "lib": ["ES2018"]
  },
  "include": ["index.js", "thing.js"]
}

Expected behavior:
I believe I should get two declaration files out of this that would look something like:

// thing.d.ts
export class Thing {}
// index.d.ts
import { Thing } from './thing';
export { Thing };

Actual behavior:
index.d.ts fails to be emitted with the error:

TS9006: Declaration emit for this file requires using private name 'Thing' from module '"/Users/neal/Desktop/privateNameTSC/thing"'. An explicit type annotation may unblock declaration emit.

It's not clear to me how to annotate the module.exports to make the "name" not private anymore
Thanks for taking a look.

Playground Link: Can't because imports related but I made a minimum repro here: https://github.com/nbbeeken/private-name-error-tsc

Related Issues: #9865

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions