Skip to content

Conversation

@Inori-Lover
Copy link

实现了个type-safe的plugin;

实践下来的想法是:

  1. plugin最后的类型校验体验不好,大致解释:
    1.1. defineStore函数用了很多推导,由用户代码推导类型,比如你写了 state 包含一个test,初始值是string类型,那么action拿到的store就包含这个test
    1.2. 问题来了:plugin如果要依赖state或者action,那么这个时候,你没写完你的定义时,ts会因为你没写完等原因导致推导无法进行,也就是,debounce里没法拿到action的key作为代码提示,只能等你写完之后再校验
    1.3. 也因为是推导校验,所以ts只知道你写的类型“互相不匹配”,但不知道以哪个为准,所以彪红会整个定义彪
  2. 尽量做一些类型透明的plugin,这样可以最大限度避开上边说的问题

@Inori-Lover
Copy link
Author

  1. 由于ts限制,plugin定义了就会扩展相关字段,如果你只定义没引用,就会出现typescript类型校验没错但实际会报错;算是个小坑(反正vue好多插件都这样…对象扩展这种做法在ts全是这样

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Sep 29, 2021

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: f3a5ef5
Status: ✅  Deploy successful!
Preview URL: https://d608adbd.ebook-reader.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants