Umi: RouterTypes类型定义有缺陷

Created on 17 Sep 2019  ·  9Comments  ·  Source: umijs/umi

为什么不在继承BasicRouteProps的时候声明泛型类型?
现在我想使用match.params里面的属性的时候总是提示我找不到
使用computedMatch总是要先判断不为空才能使用

interface RouterTypes<T extends Object = {}, P = {}> extends BasicRouteProps<P>

这样不是更好吗?

image

image

相关环境信息

  • Umi 版本:2.8.7
  • Node 版本
  • 操作系统
PR Welcome type(TypeScript) wontfix

Most helpful comment

目前的想到的一个解决方法是类似这样

interface IRoute extends RouterTypes {
    match: RouterTypes['match'] & { params: ParamsType };
}

All 9 comments

image

@ycjcl868 大兄弟 这个里面没有router相关的啊

看了下,可以使用 RouterTypes,使用 computedMatch,match 如需要可以 PR 一个

import { RouterTypes } from 'umi';

type IRoute = RouterTypes<{}, { code: string }>;

this.props.computedMatch.params.code

image

image
大哥你在忽悠我
@ycjcl868

屏幕快照 2019-10-11 10 05 24
我现在是加 ! 号解决。。。
@Sayid1

我直接用react-router-dom的类型了

来自阿里邮箱 iPhone版
------------------原始邮件 ------------------
发件人:handy notifications@github.com
日期:2019-10-11 10:30:05
收件人:umijs/umi umi@noreply.github.com
抄送:m sayid.zheng@aliyun.com, Mention mention@noreply.github.com
主题:Re: [umijs/umi] RouterTypes类型定义有缺陷 (#3218)

我现在是加 ! 号解决。。。
@Sayid1

You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

目前的想到的一个解决方法是类似这样

interface IRoute extends RouterTypes {
    match: RouterTypes['match'] & { params: ParamsType };
}

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

目前的想到的一个解决方法是类似这样

interface IRoute extends RouterTypes {
    match: RouterTypes['match'] & { params: ParamsType };
}

建议把这个加到 umi 文档里,挺常见的一个需求。

Was this page helpful?
0 / 5 - 0 ratings

Related issues

haiing picture haiing  ·  3Comments

zhanchengkun picture zhanchengkun  ·  3Comments

nguyenhuutinh picture nguyenhuutinh  ·  3Comments

afc163 picture afc163  ·  3Comments

onReadyL picture onReadyL  ·  3Comments