0

我想用antd ui,希望用script标签标签导入.min.js,像这样

<script src="//cdn.staticfile.org/react/15.4.1/react.min.js"></script>
<script src="//cdn.staticfile.org/react/15.4.1/react-with-addons.min.js"></script>
<script src="//cdn.staticfile.org/react/15.4.1/react-dom.min.js"></script>
<script src="//unpkg.com/antd/dist/antd.min.js"></script>

我的 webpack.config.js 是

externals: {  
    "react": "React",  
    "react-dom": "ReactDOM",  
    "antd": "antd"  
},  

tsconfig.json 是

{  
"compilerOptions": {  
    "module": "commonjs",  
    "target": "es5",  
    "allowJs": true,  
    "noImplicitAny": false,  
    "sourceMap": false,  
    "jsx": "react",  
    "watch": true,  
    "typeRoots": ["./h"],  
    "traceResolution": true,  
    "lib": [  
        "es6",  
        "dom"  
    ]  
},  
"exclude": [  
    "node_modules",  
    "src/server/assets",  
    "src/client",  
    "webpack.config.js"  
]  
 }  

```

首先我使用命名空间,我认为 antd objetc ptotype 中的 antd 函数如全局模块,如 jquery。

/h/antd/index.d.ts

import * as React from "react";

declare namespace antd{
    export let DatePicker: typeof React.Component;
}

declare namespace JSX {
    interface IntrinsicElements {
        "DatePicker": any;
    }
}

```

import * as antd from "antd";
let DatePicker: typeof React.Component = antd.DatePicker;

ReactDOM.render(
    <DatePicker />,
    document.querySelector("#app")
);

他们给了我一个错误:找不到 antd 模块。

我正在尝试定义一个模块

import * as React from "react";


declare module "antd2"{
  export let DatePicker: typeof React.Component;
}

declare namespace JSX {
    interface IntrinsicElements {
    "DatePicker": any;
    }
}

我再次得到错误:找不到模块

如果我把 antd2 的 floder 拷贝到 node_modules/@types ,我发现 is 的工作,为什么?</p>

所以我尝试将koa类型复制到h floder,我发现koa不起作用,为什么?</p>

我给了我的h/all.d.ts declare module "*",我还是报这个错。为什么?</p>

中的所有错误示例代码https://github.com/MiYogurt/ts-koa-react/tree/error

3Q为你助力!</p>

4

1 回答 1

1

我建议你在开发中使用 CommonJS 版本的 antd,这样你可以免费使用 antd 的类型声明,并且你可以在构建生产包时将 antd 配置为外部依赖。

于 2017-02-18T08:31:39.607 回答