i灣使用antd UI,並希望使用腳本標記標籤進口.min.js
,這樣複製node_module/@型/ KOA到我的自定義typeRoots,爲什麼不工作呢?
<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函數在antd objetc ptotype,像全局模塊,就像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模塊。
,我試圖定義一個modlue
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/@類型,我找到的是的工作,爲什麼?
所以我儘量興亞類型複製到h floder,我發現興亞是不行的,爲什麼呢?
,我給我的h/all.d.ts
declare module "*"
,我仍然得到這個錯誤。爲什麼呢?
所有https://github.com/MiYogurt/ts-koa-react/tree/error
3Q錯誤示例代碼爲您的幫助!