question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Proposal] Add type definitions via d.ts files around public API surface

See original GitHub issue

Things I’ve reviewed

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:closed
  • Created 4 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
daKmoRcommented, Aug 1, 2019

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

0reactions
daKmoRcommented, Aug 25, 2019

types for testing has been implemented in https://github.com/open-wc/open-wc/pull/697

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found