本文整理汇总了TypeScript中tns-core-modules/utils/types.isNullOrUndefined函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isNullOrUndefined函数的具体用法?TypeScript isNullOrUndefined怎么用?TypeScript isNullOrUndefined使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isNullOrUndefined函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Error
export function assertEqual<T extends { equals?(arg: T): boolean } | any>(actual: T, expected: T, message: string = '') {
if (!types.isNullOrUndefined(actual)
&& !types.isNullOrUndefined(expected)
&& types.getClass(actual) === types.getClass(expected)
&& types.isFunction(actual.equals)) {
// Use the equals method
if (!actual.equals(expected)) {
throw new Error(`${message} Actual: <${actual}>(${typeof (actual)}). Expected: <${expected}>(${typeof (expected)})`);
}
}
else if (actual !== expected) {
throw new Error(`${message} Actual: <${actual}>(${typeof (actual)}). Expected: <${expected}>(${typeof (expected)})`);
}
}
示例2: assertNotEqual
export function assertNotEqual(actual: any, expected: any, message?: string) {
let equals = false;
if (types.isUndefined(actual) && types.isUndefined(expected)) {
equals = true;
} else if (!types.isNullOrUndefined(actual) && !types.isNullOrUndefined(expected)) {
if (types.isFunction(actual.equals)) {
// Use the equals method
if (actual.equals(expected)) {
equals = true;
}
} else {
equals = actual === expected;
}
}
if (equals) {
throw new Error(message + " Actual: " + actual + " Not_Expected: " + expected);
}
}
示例3: function
export var testLoadHTMLString = function () {
let page = helper.getCurrentPage();
let htmlView = _createHtmlViewFunc();
page.content = htmlView;
// >> htmlview-using
htmlView.html = '<span><font color="#ff0000">Test</font></span>';
// << htmlview-using
if (htmlView.ios) {
TKUnit.assert(!types.isNullOrUndefined(htmlView.ios.attributedText), "HTML string not loaded properly. Actual: " + htmlView.ios.attributedText);
} else if (htmlView.android) {
TKUnit.assert(htmlView.android.getText(), "HTML string not loaded properly. Actual: " + htmlView.android.getText());
}
}