Add Typescript type definitions to javascript frontend library #1413
+267
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi! I have been trying out the new WebView features in v8, and I noticed that the current frontend library is incompatible with Typescript.
I am submitting this PR to add a simple type declarations file to the existing project. Without type definitions, Typescript users either cannot use the library, or must disable type checking for this library, which means they also have no access to the JSDoc documentation you've written. This fix is similar to releasing @types types for javascript code, but as this library is not a published npm package I figure colocating the definitions may be the best solution, at least in the short term.
The only downside to this is that it creates an additional source of truth for function annotations (JS users see the original JSDoc comments, while Typescript users can only see them if they are in the
.d.ts
file.) The only better solution I know of is to fully migrate to Typescript, so for that reason it is very common to maintain types and JS code separately for libraries not originally written in typescript.Most of the
index.d.ts
file was generated automatically by the typescript compiler, plus a handful of my corrections.Let me know if I can improve anything or if I can help answer any questions about how these definitions work. I am already using them on one project and they have been working flawlessly so far.
Thanks!