【发布时间】:2016-01-12 00:39:54
【问题描述】:
一开始我导入react时,typescript编译器控制台'找不到模块react',然后我添加 /// ,问题就解决了。
但我刚刚发现如果我删除参考评论,没有错误。
这是我的代码:
/**
* Created by huagu on 2015/12/21.
*/
import * as ReactDOM from "react-dom";
import * as React from "react";
import FloatButton from "./FloatButton";
window.onload = function (event:Event) {
var bd = document.querySelector('#bd');
var style:__React.CSSProperties = {
width:'80px',
height:'40px',
background:'blue',
position:'absolute',
top:'100px',
left:'10px'
}
var str:__React.CSSProperties = '';
var num:number = '';
var c = <span style={{fontSize:'14px'}}>button</span>
var props = {
content:c,
click:function(){
console.log("FloatButton clicked");
},
style:style,
allowSeriesClick:false,
}
ReactDOM.render(<FloatButton {...props}></FloatButton>, bd);
}
所以,我的问题是是否需要引用注释?我没有添加引用注释,但是没有错误引用__React.CSSProperties,它是在react.d.ts中声明的。如果没有必要,为什么“var str:__React.CSSProperties = '';”没有错误?
【问题讨论】:
标签: reactjs typescript