Skip to content

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

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';classThing{}module.exports={ Thing };
// index.js"use strict";constThing=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.tsexportclassThing{}
// index.d.tsimport{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

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions