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

[JS] accessing nested namespaces from require() with destructuring leads to an error #41699

Open
sokra opened this issue Nov 26, 2020 · 2 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@sokra
Copy link
Contributor

sokra commented Nov 26, 2020

TypeScript Version: 4.2.0-dev.20201126

Search Terms: TS2305

Code

// Must be in JS mode, works in TS mode
const { HttpUriPlugin } = require("webpack").experiments.schemes;
// TS2305: Module '"webpack"' has no exported member 'schemes'.

// Syntax equivalents that work:
const schemes = require("webpack").experiments.schemes;
const HttpUriPluginAlternative1 = require("webpack").experiments.schemes.HttpUriPlugin;
const { schemes: { HttpUriPlugin: HttpUriPluginAlternative2 } } = require("webpack").experiments;

console.log(HttpUriPlugin);
console.log(schemes.HttpUriPlugin);
console.log(HttpUriPluginAlternative1);
console.log(HttpUriPluginAlternative2);

Expected behavior:

Destructuring a nested namespace in JS mode doesn't lead to an error

Actual behavior:

An error is emitted.

The error also looks a bit weird:

Module '"webpack"' has no exported member 'schemes'.
Something like Namespace 'experiments' has no exported member 'schemes'. would make more sense.
It seems like it looks up schemes on the wrong type...

Playground Link: Link

Related Issues:

@sk-
Copy link

sk- commented Nov 27, 2020

Seems that the culprit may be #39770, as there are many similar issues. The palyground link works with 4.0.5 but fails with version 4.1.2.

sokra added a commit to webpack/webpack that referenced this issue Nov 30, 2020
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Dec 3, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.2.0 milestone Dec 3, 2020
@sandersn sandersn added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Bug A bug in TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Feb 3, 2021
@sandersn sandersn modified the milestones: TypeScript 4.2.1, Backlog Feb 3, 2021
@sandersn sandersn removed their assignment Feb 3, 2021
@sandersn
Copy link
Member

sandersn commented Feb 3, 2021

I couldn't find any other code bases that try the combination of property accesses and destructuring. This is indeed an incorrect outcome that neither the ad-hoc alias resolution code nor the synthetic-type fallback correctly handle, but I'm not sure it's worth complicating the already-bizarre code unless we find out that lots of people want to write this code.

@RyanCavanaugh RyanCavanaugh removed the Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature label Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants