wechat-miniprogram / mobx-miniprogram-bindings

小程序的 MobX 绑定辅助库
MIT License
206 stars 20 forks source link

结合TS使用`ComponentWithStore`时,无法在`this`上找到action方法 #53

Open kkaatii opened 3 weeks ago

kkaatii commented 3 weeks ago

实例代码片段如下:

ComponentWithStore({
    storeBindings: {
        store,
        fields: ...,
        actions: {
            update: 'updateNum',
        },
    },
    methods: {
        submit() {
            this.update(...) // 报错说`update`在`ComponentWithStoreInstance<...>`上不存在
        },
    },
})
LastLeaf commented 2 weeks ago

用的版本是?

LastLeaf commented 2 weeks ago

请参考 #47 和 #51 。

kkaatii commented 2 weeks ago

你们更新了src/index.ts,但是TS类型推导使用了types/index.d.ts。后面这个文件里的类型定义还是3.X版本的。

LastLeaf commented 2 weeks ago

Sorry 。 4.0.0 发布有问题,发布了 4.0.1 来修复。

LastLeaf commented 2 weeks ago

另外, actions 段的末尾需要加一个 as const ,如:

    storeBindings: {
        store,
        fields: ...,
        actions: {
            update: 'updateNum',
        } as const,
    },