-
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
"Foreign" type in Interaction
in scenegraph
module
#54
Comments
Yes! The problem you have here is that the Whenever you export a class, you make its constructor available to importers. Lots "classes" in the XD API do not allow instances. At the very least the constructor should be marked // OUTPUT: Object
console.log(require('interactions').constructor.name); The In this case, I would suggest the following:
The above done, you will be able to
Either way should work fine now! |
@ericdrobinson The problem I have with this is that this would – if I'm not mistaken – "suggest" that one can actually import this type (and possibly use it for |
I've now solved this by moving those typedefs to the global namespace (in the |
@pklaschka In this case, you are indeed mistaken. It took me a while to understand this as well, but there is a very important distinction between a When you define a interface MyObject {
new (): MyObject;
}
let MyObject: MyObject; For a more complete example, check out the type declaration for
By declaring the constant So, when you declare a
Please give the version I suggested a try. The global approach is strictly worse for two reasons:
In my tests (in VSCode) with the // ERROR: Property 'Interaction' does not exist on type 'typeof interactions'.
let x = selection instanceof require('interactions').Interaction; Which is expected as the For the record, VSCode's IntelliSense doesn't even suggest the |
@ericdrobinson Understood. This, then, holds true for other modules as well, doesn't it? Specifically, I'll have to change |
|
Alright, in that case, this issue should be get resolved with the PR as well. If there are no more issues within the next two hours 😆, I'll merge the PR... |
Was about to write something along the lines of "Yes" but you beat me to it! If you attempt to do the following in XD you get an error: const viewport = require('viewport');
let v = new viewport(); // <-- Plugin TypeError: viewport is not a constructor So these should be declared as |
And, of course, @ericdrobinson: Thanks a lot (again) for your contributions. The great thing is that not only does this increase the quality of the typings, but I also feel like I have a better understanding of how TypeScript works now, so thanks on that "front" as well 👍 |
@pklaschka Happy to help! I'm very glad to hear that the conversation has helped you advance your understanding of TypeScript. That was a large portion of the motivation to provide suggestions with explanations instead of a monolithic PR with everything already packaged up. And, honestly, this process clarified more TypeScript stuff for me as well! 😄 The one final question that I have is about the |
@ericdrobinson Nope. Unfortunately, WebStorm lets you decide if you
Therefore, as long as this (or these – counting |
Sounds good to me! I expected that it might be an environmental thing. Still not entirely sure where VSCode infers that definition from, but c'est la vie. |
Also, two more things:
|
No idea, fixed in 8f7bd4f
Again, I have no idea. Whyever, it appears to work for scenegraph (imports work without any problems)... I have no idea what the decisive difference between |
I hate to rehash this now after You mentioned here that you used As I understand things, using
I saw no errors in VSCode. Do you see errors in WebStorm if you try this pattern? |
@ericdrobinson I have no idea why, but now, this works... Does that mean that all the other things (application etc.) should get exported another way as well? |
At least I now think I've got an idea of why WebStorm couldn't resolve this before. Somehow, changing the branch messed up my project configuration (no idea why), resulting in some strange way of WebStorm interpreting only parts of it... Sorry about that. |
Basically, yes. But that said, it would be better, I think, to try a different approach. Please let me know if this works for you in
This is a quick test - the only items that should actually be exported are those that you want visible from outside of the module (read: internal types should not be exported). However, find-and-replace is a quick way to get a sense of whether this works or not... |
@ericdrobinson Yep, that works. |
Doing the above in VSCode changes the suggested property interpretation. Individual Resolved names are different because of the global find-and-replace for a quick test. For reference, those icons mean "Variables and Fields" and "Classes" respectively. |
Ok. That makes sense so far. |
If you're okay with it, I would suggest changing the export process to be of this latter approach ( |
@ericdrobinson Doing so right now 😉 |
PR should now be up-to-date with this way of exporting... 😅 |
Cool. I'll take a look. I've spotted something... unexpected with this route that I want to check on. |
It works for the |
@pklaschka Let me look into it a bit. I say that because I think this is the "correct" path. The structure I suggested appears to be how you're 'supposed' to declare ambient modules. Let me quickly check the |
Correction: All hell breaks loose in WebStorm when I do that. It simply "accepts" everything as "correct" code and does no type checking or autocompletion whatsoever... |
@ericdrobinson I was able to get everything to work as expected by having interface Shell {
[...]
} instead of declare class Shell {
[...]
} cf. b0a1352 |
Did you try: class Shell {
[...]
} ? The problem should have been the |
I mentioned above that you need to get rid of I also suggested that you re-add the |
"A declare modifier is required for a top level declaration in a .d.ts file" for |
Just to be clear: By
I meant without the "ambient module" declarations... |
How about with the "ambient module" approach? |
=>
|
Does that include removal of the Also, did you try restarting WebStorm? (I've had to do that with VSCode in the past to get the language server to fully refresh...) |
Unfortunately, yes. The problem remains. |
With the shell being an interface (and no ambient modules), however, everything appears to be working as expected in WebStorm and VSCode. (basically the way it is at b0a1352). According to the documentation, |
Yes, but the type information is incorrect. |
Let's provide an extremely simple test case. Please do the following:
Do you get any errors with any of that? |
According to the documentation, Shell should be a global class. However, |
It isn't that I get any errors with ambient modules. It is the fact that I'm not getting ones, e.g., const notMyShell = require('uxp');
notMyShell.openExternal('...'); Doesn't show an error. Basically, WebStorm just "gives up" on understanding the typings with the ambient modules and still provides some autocompletion, but doesn't actually "understand" the type flow (an object is of a certain type |
|
Yeah, that actually should be |
Okay, so it looks like declaring a class within a module will also cause it to export the name. If we want a type to exist in/for a module, then we need to use Seems as though your approach of converting any I tested the |
I actually just tested this myself and wanted to write the exact same thing. So, I'll leave it the state it is in (b0a1352) and merge it? If you'd like / you agree, I'd like to add you to the contributors list in the {
"name": "",
"email": "",
"url": ""
} |
A few last minute items! Repo Structure - New Issue?I would like to suggest that the Thoughts? Inaccessible Types ComplicationI did a quick test of the // Output:
//
GraphicNode,Rectangle,Ellipse,Line,Text,Path,Group,Artboard,BooleanGroup,RepeatGrid,SymbolInstance,LinkedGraphic,Matrix,Color,LinearGradient,RadialGradient,ImageFill,Blur,Shadow,root,selection,Polygon
console.log(Object.getOwnPropertyNames(require('scenegraph'))); When you compare those to the list of types currently available from This is a bit more complicated because classes "extend" from Boo. I'm still playing around with this... Contributor InfoThanks! I appreciate it.
|
The thing is that this would mean that the Therefore, while I understand the request, it's a bit more complicated than that and I'd, therefore, suggest having this in a new issue discussing solutions and "apart" from the current Pull Request.
Interesting – one of my projects actually relies on such a type check. I guess it's time to hotfix that. However, I'd like to defer this into another pull request (as soon as we find a better-suiting solution) to not explode the current PR even further than it already is. Since the PR is mostly structure-related and this is an actual "content" mistake, that sounds like something that's going to be easy to merge with the next bigger update.
Perfect, thank you. You're now added to the contributor list. I'll now merge the Pull Request and open new issues for the two ideas to keep this (slightly) organized. After all, this is the 56th comment on this issue and we're already far off-topic from the original issue title 😉 |
moved to #57
moved to #56 |
@ericdrobinson Any ideas? Since the type gets defined in the
interactions
module, it doesn't get recognized insidescenegraph.d.ts
. Should this then be defined in theindex.d.ts
as global?Thank you very much in advance.
The text was updated successfully, but these errors were encountered: