microsoft / microsoft/TypeScript

Ability for checker to resolve modules by node similar to program when providing custom host

Aperta
#61,941 7 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔍 Search Terms

module resolution location

✅ Viability Checklist
⭐ Suggestion

The program provides the ability to resolve modules based on the specific string literal node, but the checker only resolves based on specifier text and node resolution mode. This means that if module specifiers with the same text and resolution mode resolve to different modules, the checker will always resolve to the same module based on whatever was last inserted into the program's ModeAwareCache.

https://github.com/microsoft/TypeScript/blob/47ca599979c418ade9b0a2f4107c305822472e44/src/compiler/program.ts#L1973-L1975

📃 Motivating Example
import text from "./data.txt" with { type: "text" };
import bytes from "./data.txt" with { type: "bytes" };
const { default: textDynamic }   = await import("./data.txt", { with: { type: "text" }});
const { default: bytesDynamic } = await import("./data.txt", { with: { type: "bytes" }});

let invalid: number;
invalid = text;
invalid = textDynamic;
invalid = bytes;
invalid = bytesDynamic;

let validText: string;
validText = text;
validText = textDynamic;

let validBytes: Uint8Array<ArrayBuffer>;
validBytes = bytes;
validBytes = bytesDynamic;

Currently outputs:

[ERROR]: Type 'Uint8Array<ArrayBuffer>' is not assignable to type 'number'.
invalid = text;
~~~~~~~
    at file:///V:/scratch/main.ts:7:1

TS2322 [ERROR]: Type 'Uint8Array<ArrayBuffer>' is not assignable to type 'number'.
invalid = textDynamic;
~~~~~~~
    at file:///V:/scratch/main.ts:8:1

TS2322 [ERROR]: Type 'Uint8Array<ArrayBuffer>' is not assignable to type 'number'.
invalid = bytes;
~~~~~~~
    at file:///V:/scratch/main.ts:9:1

TS2322 [ERROR]: Type 'Uint8Array<ArrayBuffer>' is not assignable to type 'number'.
invalid = bytesDynamic;
~~~~~~~
    at file:///V:/scratch/main.ts:10:1

TS2322 [ERROR]: Type 'Uint8Array<ArrayBuffer>' is not assignable to type 'string'.
validText = text;
~~~~~~~~~
    at file:///V:/scratch/main.ts:13:1

TS2322 [ERROR]: Type 'Uint8Array<ArrayBuffer>' is not assignable to type 'string'.
validText = textDynamic;
~~~~~~~~~
    at file:///V:/scratch/main.ts:14:1

Found 6 errors.

If I swap the last two dynamic imports then it will error on validBytes instead of validText.

💻 Use Cases
  1. Implementing bytes and text imports in Deno (which will be unstable and is currently non-standard: https://github.com/whatwg/html/issues/9444)

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 leggendo la logica citata della risoluzione dei moduli in src/compiler/program.ts intorno alle righe 1973-1975, quindi segui il modo in cui il checker risolve gli import nell’esempio motivante. Il lavoro è completo quando la risoluzione del checker può usare il nodo specifico dello specificatore di modulo, così che testo e modalità di risoluzione identici possano risolversi in moduli diversi.

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

Valutazione

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.