-
Notifications
You must be signed in to change notification settings - Fork 8
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
Fix type declarations for options objects in uxp.d.ts #49
Comments
Thanks for bringing this up. I'll probably go with option 1, but don't have the time right now. I'll probably do this in about 3-4 weeks (and merge it with the next update), so if anyone has the time and wants to contribute – feel free to do so. Thanks again, @ericdrobinson, for your help 👍 . |
Update: I got to tackle this sooner than expected. The PR is open, I'll wait a few days (since it isn't really a pressing issue) and if there's no veto, I'll merge it. Again, thank you for all your input, @ericdrobinson (I was mostly doing the typings by trial and error, so some knowledge like yours really helps immensely to get them working as expected). |
@pklaschka Overall looks pretty excellent! I've added some inline comments to suggest further enhancements. A bit of a code review, if you will... Oh, three more things I noticed while going over the code:
Hope this helps! |
I've now fixed [1.] and [2.]. With [3.], the thing, however, is that if I don't use the As soon as I add the Thanks very much in advance. |
The way I understand it, the |
That's super weird. VSCode does not have that issue. To be clear, I'm running TypeScript v3.5.1 (the version that comes with the latest VSCode). Can you verify your version of TypeScript? If it's not 3.5.1 then it could be that what I'm experiencing is effectively a new bug on the TypeScript side of things. What's more, I was previously unaware that XD/UXP didn't support ES6 I did a quick search of issues over on TypeScript and it looks like someone else has already called out the fact that TypeScript 3.5.1 sees this construction as problematic. Hmm... |
@ericdrobinson I do seem to have a version of 3.2.1 installed globally. WebStorm, however, appears to work without TS, meaning whatever interprets the typings in there probably isn't using a particular (or at least probably not this one) version of TypeScript. However, VSCode as well has worked before I installed TS globally (via npm), meaning I'm not sure where that's taking its interpreter from either... Since I really have no idea what's going on right now, I'll just write down here what I know and hopefully, we'll be able to continue from there 😉:
|
I've spoken with @kerrishotts a bit about the module construction behind this module a bit. Here's a snippet of that conversation:
So it looks more like happenstance that the XD import process works a lot like the CommonJS model. And further that idiomatic JavaScript imports may be feasible at some point in the future. I'm somewhat of two minds on this one...
Anyone from Adobe have any thoughts on this one? |
@pklaschka It is highly likely that your WebStorm install is using either the bundled version. You can verify what it's using by checking out the TypeScript preferences page. It does not work on "nothing" ;) Same goes for VSCode. When you're editing a TypeScript file (like You can also configure a custom version. |
@ericdrobinson Ah, ok. I thought it might be using some "custom" interpreter (I should definitely try to find the time to learn a bit more about the technical side of this 🙂 ). The behavior mentioned above is using TypeScript 3.4.1 in VSCode and WebStorm, from the looks of it... |
I can confirm that with TypeScript 3.5.2 (which I've just installed as the latest version via npm), WebStorm (configured to use this new version) still shows the same behavior as mentioned above. So either, this is a VSCode issue, an issue in TS 3.5.1 that got fixed in 3.5.2 or it is independent of the TypeScript version (in which case, we'd be back at the beginning)... |
Hmm... unfortunately the changelog for 3.5.2 is completely useless right now. None of the listed Changes appear super promising either. Very strange... |
@ericdrobinson Thank you very much in advance 👍 |
@pklaschka No problem! I posted the problematic code to the TypeScript bug but neglected to do so here. 🤦♂️ Put this in your /** @type {import('uxp').storage.Folder} */
let folder; In VSCode 1.35.1 with the TypeScript compiler set to either 3.5.1 or 3.5.2 the above code causes an error. |
@ericdrobinson WebStorm doesn't seem to "know" this syntax no matter how it gets implemented in the typings: VSCode – for me – behaves the same way it does for you. In WebStorm, however, using the class name without import statements appears to work fine: 😐 |
@ericdrobinson In this case, while I understand the importance of doc comments (after all, the whole reason for this issue is that I've previously preferred those doc comments instead of TS notation 😉), I would go for allowing autocompletion in as many IDEs as possible as my first priority, meaning that as long as we can't find a way to deal with this in a better way, we'd keep it as it is. While it would hurt me if doc comments wouldn't work as well as possible, I can't give a syntax for which I can't even find formal documentation in front of autocompletion in more editors. Therefore, if we can find a solution that works for both "topics", perfect. If we, however, cannot, I'd go with the way it currently is... |
@pklaschka Thanks very much for the detailed writeup of your attempts to duplicate the issue I've identified. With the information you provided, I believe I may have an explanation for what's going on.
This is likely due to a number of factors. Here are two large ones:
Taken together, it seems clear that WebStorm's JavaScript analysis and development features are powered in an entirely different way from VSCode's. In VSCode, JavaScript language services (e.g. type checking, IntelliSense) are all backed by the TypeScript language server. It turns out that VSCode also supports most JSDoc features in JavaScript. Let's get back to the point in the quote above. VSCode likely understands the That said, 👍👍 for identifying the syntax that works with WebStorm! [Unfortunately, that same syntax doesn't work for VSCode...]
That is entirely fair. I did find where that was defined but it's not in the JSDoc docs. It's in TypeScript's "Type Checking JavaScript Files" docs! Specifically, here is the list of supported JSDoc tags and here is the documentation for using What's important to identify here is that this is non-JSDoc-standard! It is specifically a "JSDoc when interpreted by the TypeScript language server" thing. Based on the discussion above, it seems plain as day that WebStorm would be all ¯\_(ツ)_/¯ about it while VSCode would say 👍. There's one very important distinction that all of this makes pretty clear: we need to be clear when we talk about JSDoc context. Is this JavaScript-side JSDoc or TypeScript-side? My assumption is that the TypeScript language server understands these JSDoc tags while the IDEs (WebStorm, VSCode) understand far more JSDoc tags and present them in their own way (VSCode mysteriously adds a newline between the For my part, I'm sorry that I wasn't more clear about the different contexts of all of this and will endeavor to be more clear in the future.
Makes sense to me! Setting aside the issue of " I'll describe that in a followup comment. |
This probably belongs in another issue, but I'll reference it in this Issue for now as I originally mentioned it here. First, some setup:
If you want, you can go through another step of creating a let x: import('uxp').storage.Folder; That will cause the same error I was describing for the JavaScript context with the Setting aside the
The first is easily rectified. Simply add an empty The second... well, that one is related to something we've already discussed. The documentation that you pointed to above has the following to say about this syntax:
The important thing here is that list of what can be on the right side of the In my local tests, I was able to get the issue to disappear by doing the following:
Once I made those changes, all of the errors disappeared. Mind checking that out to see if you can replicate the errors I encountered above and, if so, whether the steps above resolve the issue for you as well? |
This sounds really promising – thanks again for your efforts. |
I reached out through the grapevine to someone on the WebStorm dev team about WS type checking and the
On the |
Ok, I've checked this (d366aed) and it appears to be working. Would you mind checking the Pull Request version to see if everything in there is working for you as well? WebStorm has no problems with it, I haven't seen any problems occurring in VSCode or TypeScript compilation (although I'm no expert in those two 😉)... If everything's working for you in there, I'd go ahead and merge the PR. Thank you very much in advance 👍 . |
Oh, I set |
Yep. I'm still unsure what it really is. It is documented as a "global class", but as we've seen with the "static" classes, this "Kind" field of the docs really doesn't say anything. Since the only way to get an instance of it, I've now decided to move its declaration into the module...
👍 🙏 |
After the two typo (😉) fixes, I get no more issues! LGTM! |
While TypeScript theoretically supports declaring one-off types with the JSDoc format, it doesn't work terribly well for ambient type declarations (
*.d.ts
). It appears to mainly provide context for type checking the usage of that type in the body of a function's definition.Let's look at an example with the
Entry.copyTo
function. Here is how it's currently defined:As written, the TypeScript language service is already confused about the use of the
@param
directive. See:Whoops! It didn't identify the
options.overwrite
parameter correctly. To do this in a way that satisfies TypeScript, we would write the following:Oddly, once you write it "correctly" for TypeScript, the
option
object's parameters disappear from the IntelliSense entirely:Unfortunately, constructing the parameters in this way also doesn't help the language service with type checking. If you look at the type of the
options
parameter in that declaration it is consideredany
.Oh no!
A much better and safer way to handle this is to implement the options parameters inline inside the declaration. Here's an example that uses the
copyTo
function:[Note: The above version includes an updated body based on the current docs.]
With this approach we get the following three benefits:
Another Option...
If inline parameter documentation is unappealing, there is one other method that could be used. It's more flexible, but less "precise" when it comes to Adobe's documentation. Specifically, you could define your own interface:
With the above, you would change the declaration of
copyTo
to the following:This provides the same exact benefits as the inline approach with one additional benefit: you can reuse that type!
That said, it is unlikely that many people would use such a feature...
The text was updated successfully, but these errors were encountered: