microsoft / microsoft/TypeScript

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

Ouverte
#61,941 7 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Awaiting More Feedback Suggestion
Langage dominant
Go
Étoiles
111k
Forks
14.3k
Merge moyen
2 j 4 h
PR mergées (30 j)
132

Description

🔍 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)

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par lire la logique citée de résolution des modules dans src/compiler/program.ts autour des lignes 1973-1975, puis suivez la manière dont le checker résout les imports dans l’exemple motivant. Le travail est terminé lorsque la résolution du checker peut utiliser le nœud spécifique du spécificateur de module, de sorte qu’un texte et un mode de résolution identiques puissent être résolus vers des modules différents.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
typescript
Domaine
compilers
Type d'issue
Fonctionnalité
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
42/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.