Skip to content

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

Open
@sokra

Description

@sokra

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions