amark / gun

An open source cybersecurity protocol for syncing decentralized graph data.
https://gun.eco/docs
Other
18.05k stars 1.16k forks source link

New GUN typings #1205

Closed orimay closed 2 years ago

orimay commented 2 years ago

Old TS definitions were not covering many use cases and were lying about some types (like that get returns a promise).

Also, new type definitions cover some undocumented stuff, like those on hooks we were planning to discuss, e.g. create, opt, in, out, get, put, hi, bye — they are all typed now.

Also, almost no deprecated methods have typings now.

Made it so that optional libs (like then, promise) types only imported on such libs import, so no type suggestions occur for non-imported libs anymore

j-waters commented 2 years ago

Won't this remove a lot of type information? https://github.com/amark/gun/wiki/TypeScript-Guide won't work anymore

orimay commented 2 years ago

Isn't this page related to @types/gun package?

j-waters commented 2 years ago

It was, but the example there works with the version in the repository without @types/gun. The current definition for the gun constructor is:

new <DataType extends IGunDataType= IGunDataType>(options?: IGunConstructorOptions): IGunInstance<DataType,undefined>;

which allows you to define the structure of your GUN database, whereas in this PR it's:

new (options?: GunOptions): IGunInstance;

Don't get me wrong, the current typings aren't 100% correct and I'm sure this PR solves a lot of issues (I first came across it because in the current version the types for .map() are wrong but yours are right), but it'd be a shame to lose the functionality laid out in that wiki article.

orimay commented 2 years ago

I see. I'm a bit busy lately, but I'll take a look at if I'll be able to make it work with generic GUN instance the way it currently does

orimay commented 2 years ago

I think I nailed it. Gonna check it on my pet project first before push

orimay commented 2 years ago

I think it's ready now :)

amark commented 2 years ago

HOLY MIND BLOW!!!!!!!!!!

What an amazing incredible labor of love.

⭐ ⭐ ⭐ ⭐ ⭐ ⭐ ⭐ ⭐ ⭐ ⭐ ⭐ ⭐ ⭐ ⭐ ⭐ ⭐ ⭐ ⭐ ⭐ ⭐ ⭐ ⭐ ⭐

I'm angry that @amark didn't merge this earlier. We should pester him.

(seriously, don't be shy. I know I'm delayed a lot, but sometimes its that I didn't even get a notification)

You know what this means right? I'm going to ask you to write a script/bot that will automatically pull all your comments & paste them into docs please please please please?

orimay commented 2 years ago

But my comments mostly come from your docs. Also, I believe, docs need a separate look

sascha1337 commented 1 year ago

ts-gun wen