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
@types/gun incompatible with React CRA / Babel #37344
Comments
Yes although ESModule is good to use, sadly the |
Actually, it seems namespace support was merged into babel. Maybe I just need a bleeding edge version. |
@Jack-Works, Looks like namespace support is in the latest version of |
I'm sorry when writing typing for gun, I didn't consider it clearly. There is no way to import ChainReference and type is very unfriendly with untyped code. When I'm free, I'll try to resolve this problem. |
@Jack-Works okay, thank you for you help with this. I think I found a good temporary solution:
This seems to be working, but now I'm seeing other problems I don't understand. If I try to use
Is this just a mistake? I see the same issue with
|
@Jack-Works have a look at this code, this compiles and runs as expected. I've cast I can start submitting PR's as I find these issues. |
diff --git a/types/gun/index.d.ts b/types/gun/index.d.ts
index 0cba9d6620..1d1813fcbe 100644
--- a/types/gun/index.d.ts
+++ b/types/gun/index.d.ts
@@ -86,7 +86,7 @@ declare namespace Gun {
* @param callback invoked on each acknowledgment
*/
put(
- data: Partial<AlwaysDisallowedType<DisallowPrimitives<IsTop, DisallowArray<DataType>>>>,
+ data: string | number | boolean | { [p: string]: string | number | boolean },
callback?: AckCallback
): ChainReference<DataType, ReferenceKey, IsTop>;
/**
@@ -102,7 +102,7 @@ declare namespace Gun {
* **Here the type of callback respect to the actual behavior**
*/
get<K extends keyof DataType>(
- key: ArrayOf<DataType> extends never ? K : never,
+ key: string | ChainReference,
callback?: (
/** the raw data. Internal node of gun. Will not typed here. */
paramA: Record<
@@ -156,7 +156,7 @@ declare namespace Gun {
*/
once(
callback?: (
- data: (DisallowPrimitives<IsTop, AlwaysDisallowedType<ArrayAsRecord<DataType>>>) | undefined,
+ data: string | number | boolean | (DisallowPrimitives<IsTop, AlwaysDisallowedType<ArrayAsRecord<DataType>>>) | undefined,
key: ReferenceKey
) => void,
option?: { wait: number }
@Jack-Works, here's some changes I made in the type definitions. I cloned this to my local and used |
It's by design. With typed interface, methods like |
Could you elaborate? Maybe include an example? Shouldn't |
You can see the test example in the @types/gun |
I understand now. In the next version, will |
Yes, I'll find time to do that when I'm free.
…On Wed, Aug 7, 2019, 12:27 PM Rob ***@***.***> wrote:
I understand now. In the next version, will ChainReference be exported?
It might help me write the types for react-gun.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#37344?email_source=notifications&email_token=ABJEC73SLMGCLQBYVFZH7UTQDJFMRA5CNFSM4IJEOMKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3XFATA#issuecomment-518934604>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABJEC7Z2TP3GIAYIGLRFPSLQDJFMRANCNFSM4IJEOMKA>
.
|
Got no idea how to do this well, maybe I need to contribute to gun and let them to use esmodule first |
Actually I can, I know there is a change in the gun that make gun provides
esmodule export. After the export shipped, I'll use a more graceful way to
export the types.
…On Thu, Aug 15, 2019, 2:46 AM Rob ***@***.***> wrote:
@Jack-Works <https://github.com/Jack-Works>, cross-posting this question
from gitter.
Is a reason we can't export the Gun namespace? I'm having trouble typing
the following function for react-gun
<https://github.com/rm-rf-etc/react-gun>:
export const init = <AppState>(RootName: Gun.ArrayOf<AppState>, ...args: any[]) => {
const gun = Gun<AppState>(...args);
const app = gun.get(RootName);
return { gun, app };
};
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#37344?email_source=notifications&email_token=ABJEC7ZNSJNTAZRKKWNCGLTQERHJXA5CNFSM4IJEOMKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4JXTOY#issuecomment-521370043>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABJEC7ZIOJNPOEFYZWZE6RDQERHJXANCNFSM4IJEOMKA>
.
|
I have seen the experimental es module export gun, I'll rewrite the types later, make it more friendly to TypeScript and non-typescript users. |
Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the |
@types/gun
package and had problems.Definitions by:
inindex.d.ts
) so they can respond.I'm forced to find a workaround to use
@types/gun
in a create-react-app project because babel doesn't support namespaces, and likely never will. The types for GunDB are all namespaced, so this library won't work for any CRA / Babel users. Since namespaces are now considered legacy and it seems that the push is to use ES6 modules everywhere, I think it makes sense to remove namespaces from@types/gun
.To add some extra context, modifying CRA without ejecting requires some jumping thru hoops:
https://github.com/timarney/react-app-rewired/
https://github.com/arackaf/customize-cra/
FWIW, I'm trying to author a
react-gun
library.Would very much appreciate some workaround suggestions.
The text was updated successfully, but these errors were encountered: