Skip to content

Emitting declarations for commonjs exported classes suggests classes are private, TS9006 #40859

@euclideansphere

Description

@euclideansphere

TypeScript Version: 4.0.3 (also happens in typescript@next)

private name,Declaration emit,block declaration emit,TS9006

a very simple code sample -
https://github.com/euclideansphere/private-declaration-issue

// utils/errors.js
class FancyError extends Error {
	constructor(status) {
		super(`error with status ${status}`);
	}
}

module.exports = {
	FancyError
}

// utils/index.js
// issue arises here on compilation
const errors = require("./errors");

module.exports = {
	errors
}

Expected behavior:

(master)⚡ % tsc # should run clean, exit with code 0

Actual behavior:

(master)⚡ % tsc                                                                                                                                                       ~/projects/private-declaration-issue
utils/index.js:1:1 - error TS9006: Declaration emit for this file requires using private name 'FancyError' from module '"/Users/austin/projects/private-declaration-issue/utils/errors"'. An explicit type annotation may unblock declaration emit.

1 const errors = require("./errors");
  ~~~~~


Found 1 error.

Playground Link:
https://github.com/euclideansphere/private-declaration-issue

Related Issues:
#9865 - seems to be an issue with "A inherits B but only A is exported", but in this case B is a global and adding it as an export doesn't resolve the issue.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationFix 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