Typescript custom @types package for @types/react-router

我的未来我决定 提交于 2019-12-04 19:55:52

You don't need to change the original typing. You can do that using "Module Augmentation": https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation

To test, add the following module declaration after import the original module:

declare module "react-router/lib/Route" {
    interface RouteProps {
        name?: String;
    }
}

like this:

import { RouteProps } from "@types/react-router";

declare module "react-router/lib/Route" {
    interface RouteProps {
        name?: String;
    }
}

let x: RouteProps;

x.name; // <- no error!

Now you can create a file to put your custom typings (e.g. custom-typings.d.ts) on your project and put that augmentation interface.

Long answer: module augmentation. https://www.infoq.com/news/2016/03/typescript1-8-released

Short answer: file an issue or submit a PR at https://github.com/DefinitelyTyped/DefinitelyTyped

Why is the second answer shorter? Because it will probably take you less time to do.

Best

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!