这里是一个使用?
符号这是什么类型的语法,它是什么意思? “变量?:值”
export type Props = {
/**
* The CSS class name of the scroll button elements.
*/
buttonClassName?: string,
}
tabs: ?HTMLElement = undefined;
这里是一个使用?
符号这是什么类型的语法,它是什么意思? “变量?:值”
export type Props = {
/**
* The CSS class name of the scroll button elements.
*/
buttonClassName?: string,
}
tabs: ?HTMLElement = undefined;
这是用于使用流的javascript/react组件的类型转换。
让得到你的例子
export type Props = {
buttonClassName?: string,
}
这些道具出口(主要为Button类)。这意味着对于某个按钮组件,buttonClassName的一个属性是一个可选参数(由于?),其数据类型是一个字符串。如果没有?在开发环境中会引发警告。
另一个例子如何使用此方法
type ButtonProps = {
label: string,
onClick: Function,
styleClass?: {[key: string]: string}
};
class ButtonComponent extends Component<ButtonProps> {
... other code
}
现在,如果你在你的代码中使用<ButtonComponent />
你会做
<ButtonComponent
label="Confirm"
onClick={someClickHandlerFunction}
styleClass={a style object}
/>
现在注意到的styleClass的道具。语法意味着它将是一个对象,而问号意味着它是可选的。这种方式可以避免由于未定义的对象等原因而发生大量错误。
<ButtonComponent
label="Confirm"
styleClass={a style object}
/>
这将抛出一个警告,作为支撑的onClick处理不当未获通过。这样可以消除很多可能的错误。
我建议在开发时使用Atom插件来处理流水线上的代码。
谢谢!我一定会加入这个插件 –
https://stackoverflow.com/questions/37632760/what-is-the-question-mark-for-in-a-typescript-parameter-name – epascarello
@epascarello谢谢,但这是在一个.js文件。这就是我的困惑所在。 –
' - >'https://flow.org/ –