amark / gun

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

Typescript: OptionsUserAuth change property is set to a string value instead of a string type #1288

Closed philippedasilva-orizone closed 1 year ago

philippedasilva-orizone commented 1 year ago

If you try to use gun.users().auth() method using the last 4th argument to allow the end user to change his/her password using Typescript, you get an error stating that the string value passed to it isn't of the type '"newPassword"'

This is because the type is declared in gun/types/sea/OptionsUserAuth.d.ts as export type OptionsUserAuth = { change: 'newPassword' }; instead of what should be: export type OptionsUserAuth = { change: string };

There is a simple workaround that relies simply on casting the string value passed to the change property to any but it breaks typescript's proper use.

const gun = Gun();
const user = gun.user();
user.auth('alias', 'password', 
     (ack) => {}, // Do whatever you want ;)
     {change= 'myNewPassword' as any});
amark commented 1 year ago

Thanks. Do you know how to contribute type definition fixes? I don't know how to do typescript so the type definitions are entirely community contributed, so please help fix!

ViniciusFXavier commented 1 year ago

Issue fixed by https://github.com/amark/gun/pull/1309

amark commented 1 year ago

Thanks. Closing then!