Closed samreid closed 9 months ago
OK here's the patch: @jessegreenberg seem OK on your side?
That patch has other awkward behavior, unassigning @jessegreenberg for now.
Can't disable typescript inspection on the JetBrain forum: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003428920-Can-t-disable-typescript-inspection
I recreated the patch above and it actually seems to be working great.
Still, I'd like to consult with someone before committing.
@zepumph and I reproduced all those tests on his side, including testing --allowUmdGlobalAccess
in the typescript command line options in WebStorm. On @zepumph setup, we had all the same problems.
Then when applying the patch, it seemed all the problems were resolved. So @zepumph and I agreed it seems ok to commit the patch. We also had an idea that we could merge the phet-types and phet-types-with imports if we change the way the exports work in that file. I'll try that and commit if it works on my side.
Our codebase is a mishmash of window.myGlobal
and sometimes just myGlobal
. When I merged the declaration files, it brought this distinction to light, because it no longer supported both variations (why?). Here's my untested patch so far, still have around 20 errors left to go:
Also, does using the "module" mode mean types declarations need to be imported at call sites? I suspect so. That would be a change, but probably for the better. Here is my current patch, probably the same as the patch in the prior comment, but I need to shelve it now to work on other things.
This issue is getting out of hand, and it seems that in module mode, there is no way to declare a global so that it is available as both myGlobal
and window.myGlobal
. It would have to be repeated in global
and global { interface Window}
. It doesn't seem like the time to reorganize and clean all that up, and to decide on the preferable way to access globals (probably via window.
though), and enforce it. Let's keep this issue about getting the types right for lodash and addressing the TS2686 that was originally reported. @zepumph confirmed the patch in https://github.com/phetsims/chipper/issues/1402#issuecomment-1699899889 worked as intended. So let's start with that.
I added the types for lodash, and I added documentation to explain the types files, and I cross referenced them. This issue seems good to close. There is a bunch of other technical debt in phet-types.d.ts but I'm not sure when it should be addressed. Closing.
WebStorm indicates a warning
TS2686
on all usages of lodash code. I worked with @jessegreenberg to change the inspections, disable the inspections, set compiler options to allow and set command line options to allow, but WebStorm was intransigent. Instead, we found a way to import the types from the@types
declaration and re-export as a global. This has to be done in a different file, since the import wrecks the other ambientdeclare var
exports. But this seems to be working great in my IDE. Here's a patch. I'll run it past @jessegreenberg to see if it works well on his side.