npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dva-type

v1.0.3

Published

根据 dva model 的类型定义进行 state、dispatch 的 TS 类型推导,传入 model 类型定义,返回state和actions的类型定义。

Downloads

16

Readme

dva-type

安装

npm i dva-type —save-dev

说明

基于 TypeScript 4.1 版本的 Template Literal Types 特性,实现 dva models 的完整类型推导和提示。

传入项目的 models 类型定义,返回 stateactions的类型定义。

  • state 类型提示
  • action type 类型提示
  • action payload 类型推断

使用

Example

  1. 定义单个 Model 类型(注意 ModelEffect 不是从 dva 中导入的)

    import { Effect, Model } from 'dva-type'
    
    interface ListModel extends Model {
      state: {
        list: any[]
      }
      effects: {
        // 定义effect 传入 payload 类型
        getList: Effect<number>
    
        // 不需要 payload 的 effect
        getInfo: Effect
      }
    }
  2. 定义项目中所有 Model 的集合(使用 type 而不是 interface

    // 使用 type 定义 models,将项目中的所有 model 进行收集
    type Models = {
      list: ListModel
      info: InfoModel
      // ...
    }
  3. Models 传入 ResolverModels 获取 stateactions 的类型

    import { ResolverModels } from 'dva-type'
    
    type State = ResolverModels<Models>['state']
    type Actions = ResolverModels<Models>['actions']
  4. 使用

    // hooks
    useSelector<State>()
    const dispatch = useDispatch<(action: Actions) => any>()
    
    // class
    const mapStateToProps = (state: State) => {}
    interface Props {
      dispatch: (action: Actions) => any
    }