microsoft / microsoft/TypeScript
Export Typescript libraries as individual interfaces as well
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining the existing lib.dom.d.ts declaration and the proposed typescript/interface/lib.dom path; the issue names no implementation files or tests. Done would mean exposing library interfaces separately so consumers can import them without including the entire DOM library.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100