microsoft / microsoft/TypeScript
Destructuring exported array with `require` causes error
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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 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.js
class A {}
module.exports = [A]
// b.js
const [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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con la riproduzione nei due file a.js e b.js, dove module.exports assegna un array e require lo destruttura. Segui la gestione di module.exports e del require destrutturato da parte del compilatore per determinare perché viene segnalato TS2305. Il lavoro è completato quando l’esempio viene compilato senza quell’errore e il tipo del valore destrutturato viene inferito correttamente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100