microsoft / microsoft/TypeScript
Export Typescript libraries as individual interfaces as well
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.3k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
Search Terms
export library interface
Suggestion
Right now Typescript declares it's libraries using d.ts (e.g. lib.dom.d.ts) so if you include this in your project you get the entire DOM library and it's interfaces. This is great however it makes development of isomorphic code harder.
Your only option is to add the dom library to your NodeJS project. This means that consumers could accidentally write unsafe code.
My proposal is really simple. Along with existing d.ts imports, we also export (in a separate file) the interfaces for those libraries
Use Cases
Isomorphic code could be be implemented in an easier way. Right now we need to either include the whole library or use dependency injection. Which is not always trivial.
Here is an example of an issue encountered from the puppeteer repo - https://github.com/DefinitelyTyped/DefinitelyTyped/issues/24419#issuecomment-637700421
Examples
import { Window } from 'typescript/interface/lib.dom'; // proposed path
window.alert('something'); // this will throw TS errors
page.evaluate(() => {
// this will be fine and type checked according to window
(window as Window).alert('something');
});
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, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par examiner la déclaration lib.dom.d.ts existante et le chemin proposé typescript/interface/lib.dom ; l’issue ne nomme aucun fichier d’implémentation ni aucun test. Le travail sera considéré comme terminé lorsque les interfaces de la bibliothèque seront exposées séparément, afin que les consommateurs puissent les importer sans inclure toute la bibliothèque DOM.
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é
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 30/100