本文整理汇总了TypeScript中@ember/utils.typeOf函数的典型用法代码示例。如果您正苦于以下问题:TypeScript typeOf函数的具体用法?TypeScript typeOf怎么用?TypeScript typeOf使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了typeOf函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: typeOf
const isValueEquiv = (value: any, expectedType: string | Array<string>): true => {
const valueType = typeOf(value);
const isValueOfExpectedType = expectedType.includes(valueType);
if (!isValueOfExpectedType) {
throw new Error(`Expected ${value} to be of type(s) ${expectedType}, got ${valueType}`);
}
return isValueOfExpectedType;
};
示例2: typeOf
(function() {
/** typeOf */
// TODO: more specific return type in @types/ember https://github.com/typed-ember/ember-cli-typescript/issues/259
// typeOf(null); // $ExpectType 'null'
// typeOf(undefined); // $ExpectType 'undefined'
// typeOf('michael'); // $ExpectType 'string'
// // tslint:disable-next-line:no-construct
// typeOf(new String('michael')); // $ExpectType 'string'
// typeOf(101); // $ExpectType 'number'
// // tslint:disable-next-line:no-construct
// typeOf(new Number(101)); // $ExpectType 'number'
// typeOf(true); // $ExpectType 'boolean'
// // tslint:disable-next-line:no-construct
// typeOf(new Boolean(true)); // $ExpectType 'boolean'
// typeOf(() => 4); // $ExpectType 'function'
// typeOf([1, 2, 90]); // $ExpectType 'array'
// typeOf(/abc/); // $ExpectType 'regexp'
// typeOf(new Date()); // $ExpectType 'date'
// typeOf(FileList); // $ExpectType 'filelist'
// // typeOf(EmberObject.extend()); // $ExpectType 'class'
// // typeOf(EmberObject.create()); // $ExpectType 'instance'
// typeOf(new Error('teamocil')); // $ExpectType 'error'
// TODO fix upstream in @types/ember https://github.com/typed-ember/ember-cli-typescript/issues/260
// typeOf();
typeOf(null);
typeOf(undefined);
typeOf('michael');
// tslint:disable-next-line:no-construct
typeOf(new String('michael'));
typeOf(101);
// tslint:disable-next-line:no-construct
typeOf(new Number(101));
typeOf(true);
// tslint:disable-next-line:no-construct
typeOf(new Boolean(true));
typeOf(() => 4);
typeOf([1, 2, 90]);
typeOf(/abc/);
typeOf(new Date());
typeOf(FileList);
typeOf(new Error('teamocil'));
})();
示例3: testTypeOf
function testTypeOf() {
utils.typeOf(); // $ExpectType string
utils.typeOf({}); // $ExpectType string
}
示例4: typeOf
(function() {
/** typeOf */
typeOf(null); // $ExpectType "null"
typeOf(undefined); // $ExpectType "undefined"
typeOf('michael'); // $ExpectType "string"
// tslint:disable-next-line:no-construct
typeOf(new String('michael')); // $ExpectType "string"
typeOf(101); // $ExpectType "number"
// tslint:disable-next-line:no-construct
typeOf(new Number(101)); // $ExpectType "number"
typeOf(true); // $ExpectType "boolean"
// tslint:disable-next-line:no-construct
typeOf(new Boolean(true)); // $ExpectType "boolean"
typeOf(() => 4); // $ExpectType "function"
typeOf([1, 2, 90]); // $ExpectType "array"
typeOf(/abc/); // $ExpectType "regexp"
typeOf(new Date()); // $ExpectType "date"
typeOf(new FileList()); // $ExpectType "filelist"
// typeOf(EmberObject.extend()); // $ExpectType "class"
// typeOf(EmberObject.create()); // $ExpectType "instance"
typeOf(new Error('teamocil')); // $ExpectType "error"
typeOf();
typeOf(null);
typeOf(undefined);
typeOf('michael');
// tslint:disable-next-line:no-construct
typeOf(new String('michael'));
typeOf(101);
// tslint:disable-next-line:no-construct
typeOf(new Number(101));
typeOf(true);
// tslint:disable-next-line:no-construct
typeOf(new Boolean(true));
typeOf(() => 4);
typeOf([1, 2, 90]);
typeOf(/abc/);
typeOf(new Date());
typeOf(FileList);
typeOf(new Error('teamocil'));
})();