Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In JS, commonjs require imports typeof class, not class instance type. #40155

Closed
sandersn opened this issue Aug 20, 2020 · 1 comment · Fixed by #40228
Closed

In JS, commonjs require imports typeof class, not class instance type. #40155

sandersn opened this issue Aug 20, 2020 · 1 comment · Fixed by #40228
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@sandersn
Copy link
Member

From the webpack user test:

// @filename: mod1.js
class K {
	values() {
	}
}
exports.K = K;
// @filename: test.js
const { K } = require("./mod1");
/** @type {K} */
let k;
k.values();

Expected behavior:

No error, and k: K

Actual behavior:

Error "'values' not found on 'typeof K'." and k: typeof K.

Note: doesn't happen with exports.K = class { values() {} }

@sandersn
Copy link
Member Author

Also doesn't happen with export { K }; this is probably because exports.K = K doesn't create a real export alias.

@sandersn sandersn self-assigned this Aug 20, 2020
@sandersn sandersn added this to the TypeScript 4.1.0 milestone Aug 20, 2020
@sandersn sandersn added the Bug A bug in TypeScript label Aug 20, 2020
sandersn added a commit that referenced this issue Aug 24, 2020
This fixes #40155 in a surprisingly small amount of code.
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Aug 24, 2020
@RyanCavanaugh RyanCavanaugh added Rescheduled This issue was previously scheduled to an earlier milestone and removed Rescheduled This issue was previously scheduled to an earlier milestone labels Aug 31, 2020
sandersn added a commit that referenced this issue Sep 10, 2020
* Alias for `module.exports.x = x`

This fixes #40155 in a surprisingly small amount of code.

* Treat any aliasable expression as an alias

* test internal references to exported class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants