microsoft / microsoft/TypeScript
Export Typescript libraries as individual interfaces as well
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit der Untersuchung der vorhandenen lib.dom.d.ts-Deklaration und des vorgeschlagenen typescript/interface/lib.dom-Pfads; im Issue werden keine Implementierungsdateien oder Tests genannt. Als abgeschlossen gilt die separate Bereitstellung von Bibliotheksschnittstellen, sodass Konsumenten sie importieren können, ohne die gesamte DOM-Bibliothek einzubinden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 30/100