microsoft / microsoft/TypeScript

Support import maps and bare import specifiers

Ouverte
#43,326 4 commentaires 35 réactions 1 personne assignée Voir sur GitHub

@weswigham y travaille déjà.

Depuis le 22/3/2021.

Needs Proposal Suggestion
Langage dominant
Go
Étoiles
111k
Forks
14.3k
Merge moyen
1 j 19 h
PR mergées (30 j)
117

Description

Suggestion

🔍 Search Terms

  1. import maps
  2. bare import specifiers

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

As import maps are part of Chrome (as of version 89), and Firefox has given a nod of approval, it would be great if Typescript embraced this cross-package import syntax.

Import maps assume an index.html (for example) file with a script tag, e.g.:

<script type="importmap">
{
  "imports": {
    "moment": "/node_modules/moment/src/moment.js",
    "lodash": "/node_modules/lodash-es/lodash.js"
  }
}
</script>

I would suggest being able to

  1. Point to a file containing such an importmap in tsconfig and/or
  2. Just supporting bare import specifiers, based on package.json/package-lock.json, the way unpkg.com is able to do..

📃 Motivating Example

Now you can reference cross-package JS files seamlessly, without bundling tools, based on browser standards.

Workaround:

The path resolution Typescript provides is inadequate, and quite unhelpful.

The only fairly reliable workaround I've found is cloning the repo to a sibling folder of my project.

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.

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

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