本文整理汇总了TypeScript中tns-core-modules/utils/types.isFunction函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isFunction函数的具体用法?TypeScript isFunction怎么用?TypeScript isFunction使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isFunction函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}