You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm progressively adding TypeScript to an existing JS codebase. In several of our files, there is an existing pattern of exporting arrays like so: module.exports = [A, serializeA].
When requiring and destructuring this export like const [A] = require('./a'), I get an unexpected error Module '"./a"' has no exported member 'A'. ts(2305) which I believe to be a bug.
🔎 Search Terms
module has no exported member TS2305
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about module.exports
⏯ Playground Link
Not sure how to repro this in a Playground work Workbench since I believe it requires files and exports/requries.
💻 Code
// a.jsclassA{}module.exports=[A]// b.jsconst[A]=require('./a')// Module '"./a"' has no exported member 'A'. ts(2305)
🙁 Actual behavior
The compiler shows an error
🙂 Expected behavior
The compiler shows no error and the exported array is correctly destructured and the type infered.
The text was updated successfully, but these errors were encountered:
Just ran into this issue, very tricky to figure out the source of this. Nothing was working for type inference, until I tried first assigning the result of require() into a variable and only then destructuring that variable.
Using latest version:
This works:
but this doesn't work:
Having to require() into a variable, then destructuring that variable for it work doesn't seem like intended behavior.
Bug Report
I'm progressively adding TypeScript to an existing JS codebase. In several of our files, there is an existing pattern of exporting arrays like so:
module.exports = [A, serializeA]
.When requiring and destructuring this export like
const [A] = require('./a')
, I get an unexpected errorModule '"./a"' has no exported member 'A'. ts(2305)
which I believe to be a bug.🔎 Search Terms
module has no exported member TS2305
🕗 Version & Regression Information
module.exports
⏯ Playground Link
Not sure how to repro this in a Playground work Workbench since I believe it requires files and exports/requries.
💻 Code
🙁 Actual behavior
The compiler shows an error
🙂 Expected behavior
The compiler shows no error and the exported array is correctly destructured and the type infered.
The text was updated successfully, but these errors were encountered: