microsoft / microsoft/TypeScript

Missing error when awaiting dynamic import of module with 'then' export

Aperta
#24,687 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: ES Modules
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

TypeScript Version: 3.0.0-dev.20180605

Search Terms:

Code

// a.ts
export function then() { return true; }

// b.ts
async function test() {
  await import('./a');
}

// c.ts
// this is basically the same as b.ts
import * as ns from './a';
function myImport() {
  return Promise.resolve(ns);
}
async function test() {
  await myImport();
}

Expected behavior:
in b.ts: [ts] Type of 'await' operand must either be a valid promise or must not contain a callable 'then' member.
This would catch a lot of bugs with dynamic imports of modules that contain a then function. The resulting Promise will never resolve: https://github.com/tc39/proposal-dynamic-import/issues/47

Actual behavior:
No error in b.ts. The resulting type of the await is {}.

Playground Link:

Related Issues:

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo gli esempi a.ts, b.ts e c.ts con la versione di TypeScript segnalata, quindi confronta la gestione degli import dinamici con il caso del namespace di Promise.resolve. Traccia il controllo dell’operando di await e l’inferenza dei tipi degli import dinamici. Il lavoro è completo quando b.ts riporta la diagnostica relativa a un then invocabile e un test di regressione copre il caso di esportazione del modulo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.