Closed jwbth closed 7 months ago
A proposed solution to this issue is implemented in commit https://github.com/wikimedia-gadgets/types-mediawiki/pull/36/commits/e47e9ae4cc932950314dc54e75902419391f7022, from MR https://github.com/wikimedia-gadgets/types-mediawiki/pull/36.
This fix involves using an additional ExtensibleMap<V, TX>
interface, which simulates both a Map<V>
for known keys and a Map<{ [k: string]: TX; }>
for unknown keys.
There may be a simpler way to do it, Basically we could define mw.config
as Map<V> & Map<{ [k: string]: TX; }>
, but this would manage the 2 method implementations as overloads, so when writing
mw.config.get(["skin", "someUnknownKey", "stylepath"])
we would get autocompletion when writing "skin"
, but not when writing "stylepath"
since after having written "someUnknownKey"
, the linter will switch from the Map<V>
definition of the get
method to the Map<{ [k: string]: TX; }>
definition of this same method. After inlining type variables this 2nd signature simplifies to
get<S extends string[]>(selection: S, fallback?: any): { [P in S]: TX; };
so we no longer get autocompletion, but worse: properties of the result object will all have type TX
, instead of string
for skin
and stylepath
.
PR #36 got merged, so the fix mentioned above has been applied (for the next npm release).
In v1.6.0, this works for TypeScript files. It still doesn't work for JavaScript files though. Unlike TS autocompletion which is powered by typescript-language-server, JS autocompletion is IDE-dependent. So don't think there's much we can do about that.
It still doesn't work for JavaScript files though. ... JS autocompletion is IDE-dependent
It wasn't working in WebStorm, but it does work in VS Code. @jwbth you're in luck!
Relatively minor one, but the one thanks to which I decided to install this package:
wg
variables are only autocompleted (in VS Code) when you typemw.config.values.wg
, but not when you typemw.config.get('wg
.Not sure this is easy to fix, but I would welcome it.