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

Typescript: map() is ignored #1218

Closed code3z closed 2 years ago

code3z commented 2 years ago

Edit: might be solved in next version

In the current typescript API, there does not seem to be a way to use map().

If I have a type like this:

interface AppState {
  list: {
   [key: string]: { something: string }
  }
}

And I use it like this:

gun.get('list').map().get('something')

The typescript thing will ignore the map() and consider 'something' to be directly under map and throw an error.

code3z commented 2 years ago

for some more context, here's my actual usecase

type index = {
    '#': {
        [key: string]: string
    }
}
interface Indexes {
    users: index
}
interface AppState {
    // indexes under the `dataset`
    [key: string]: Indexes
}

gun.get('dataset').get('users').get('#').map().put('hi')

put('hi') throws Argument of type 'string' is not assignable to parameter of type 'Partial<{ [x: string]: string; }>'.ts(2345)

amark commented 2 years ago

@code3z check against github main. If fails, ping @Orimay .

orimay commented 2 years ago

put expects object with key/value pairs. This hasn't changed since previous Gun TS implementation