wikibase-sdk icon indicating copy to clipboard operation
wikibase-sdk copied to clipboard

Update type definitions for v7

Open MrXyfir opened this issue 5 years ago • 6 comments

@maxlath @noinkling @EdJoPaTo

In the meantime, you should push a new version without the types key in package.json so as not to give people bad types automatically.

MrXyfir avatar Jun 03 '19 20:06 MrXyfir

new version without the types: v7.0.8

maxlath avatar Jun 05 '19 07:06 maxlath

Hello, is there a status on TypeScript typings ? looking around in the issues, it seems there used to be typings but they have been deleted ? It seems also there was typings on DefinitelyTyped but they have been deleted as well ? is there an update on this ?

Thanks for your library ,

r3mi avatar Jan 15 '20 20:01 r3mi

@r3mi types were added for v6, but then v7 brought some breaking changes and those types became obsolete so were removed. I don't see any breaking change coming, so if anyone wants to update types for v7, I would be ok to merge them back. I still don't use Typescript for now, so I can't do the maintenance of those, but it seems that enough people are interested to make it happen and keep those updated.

maxlath avatar Jan 16 '20 10:01 maxlath

I created the wikibase-types npm package for types returned by the wikibase / wikidata API. Its helpful but still not as good as a fully typed library.

If someone has the time: The typings from #69 could be used to type this library on DefinitelyTyped but without this change the typings seem to get way more complicated than in #69. (Maybe I have overlooked something?)

EdJoPaTo avatar May 06 '20 17:05 EdJoPaTo

without this change the typings seem to get way more complicated than in #69. (Maybe I have overlooked something?)

That seems weird to me, usually it's not up to the library to write hacks to ensure compatibility between CommonJS and ES modules. I thought that was what the allowSyntheticDefaultImports TS compiler option did (although there are other options that can enable it implicitly), or maybe esModuleInterop.

noinkling avatar May 07 '20 04:05 noinkling

These compiler options only help, as far as i understand, to import things into your lib. The types have to be correct for that in the first place. (Correct me if im wrong!)

The problem in this case is the duplicate export of the common types. The library exports methods like isPropertyId and the WDK function and the object returned also contains the common methods.

Normally you would create a namespace and the function with the same name and export that to follow the JS code. But you can not export * from from within namespaces which creates a lot of method: typeof method stubs. On the returned interface you have to do the same which creates a lot of typing code just for that. (which is also prone to errors when something changes)

Having the default export you can simply export * from without the need for the extra namespace and have way less typing code. Also i didnt exported the common methods from the returned object which also simplified the typing code a lot (but thats far from perfect typings).

Personally I think the time invested to type this could be also spent to refactor things. But thats up to everyone themselves. I only started to look differently onto source code since I started using TypeScript and I am not used to code which is used in front end / browsers. The way this library is built certainly has its purpose.

EdJoPaTo avatar May 07 '20 07:05 EdJoPaTo

Closing in favor of #82

maxlath avatar Feb 04 '23 22:02 maxlath