[Proposal] Add type definitions via d.ts files around public API surface
See original GitHub issueThings I’ve reviewed
- Read the
types.md
- Read through some previous issues
- Read through some PRs such as https://github.com/open-wc/open-wc/pull/277
Preamble
In my opinion, the current required setup to get type hinting is way too cumbersome. Perhaps less so for Javascript, for sure; however, having to go as far as changing my build process to get type hinting only for this project’s packages is kind of a no-go. I’m not going to propose changing this project to Typescript—that’s kind of a separate matter, but I do believe getting a more frictionless experience with types is needed.
Proposal
I’d like to propose exposing type definition files (*.d.ts
) that cover the public API surface of this project. This is similar to what DefinitelyTyped does, but without having to install a separate package. As an example, several of sindresorhus’s repos follow this pattern.
Benefit
- Types work out-of-the-box without having to convert the entire source of the project.
- Can be done gradually and without impacting current source.
// @ts-ignore
comments in Javascript code would no longer be required.- Only needs to cover public API.
Downsides
- Types could fall out of sync because not tied to the source, but on the bright side, this only applied to the public API.
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (10 by maintainers)
Top Results From Across the Web
Documentation - Modules .d.ts - TypeScript
Testing your types · Create a new file in the root of your source tree: [libname].d.ts · Add declare module "[libname]" { }...
Read more >Flatten type definitions to a single *.d.ts file · Issue #139 - GitHub
In accordance with the flat ecmascript modules idea, we should create a flat <library>.d.t.s file that described the public API surface. Inspiration taken...
Read more >About "*.d.ts" in TypeScript - Stack Overflow
The "d.ts" file is used to provide typescript type information about an API that's written in JavaScript. The idea is that you're using...
Read more >TypeScript: Adding Custom Type Definitions for Existing ...
Initial Setup. Before you write custom types, you need to tell the transpiler about them. To do this you should edit the tsconfig.json...
Read more >Announcing TypeScript 4.2 - Microsoft Developer Blogs
Let's take a look at what's in store for TypeScript 4.2! Smarter Type Alias Preservation; Leading/Middle Rest Elements in Tuple Types; Stricter ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
soooo @runem made a fantastic script that might get us exactly where we want to be… until tsc supports it directly 💪
see it here… pls help verify if the output is what you would expect/need https://github.com/open-wc/open-wc/pull/678
types for testing has been implemented in https://github.com/open-wc/open-wc/pull/697