我正在为现有的 JS 库(CKEditor)编写一些定义。是否可以更具体toolbar: any
?
文档:
工具栏:数组/字符串
工具箱(别名工具栏)定义。它是工具栏名称或
工具栏(条)数组,每个工具栏也是一个数组,包含一个
UI 项目列表。
库代码:
var toolbar = editor.config.toolbar;
// If it is a string, return the relative "toolbar_name" config.
if ( typeof toolbar == 'string' )
toolbar = editor.config[ 'toolbar_' + toolbar ];
return ( editor.toolbar = toolbar ? populateToolbarConfig( toolbar ) : buildToolbarConfig() );
Typescript 1.4 现在支持联合类型
当然,您仍然需要检查函数内部的值并做出相应的反应,但是现在您可以进行编译时检查,而无需将类型更改为any
.
function f(x: number | number[]) {
if (typeof x === "number") {
return x + 10;
}
else {
// return sum of numbers
}
}
http://blogs.msdn.com/b/typescript/archive/2015/01/16/announcing-typescript-1-4.aspx http://blogs.msdn.com/b/typescript/archive/2015/01/16/announcing-typescript-1-4.aspx
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)