当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript utils.typeOf函数代码示例

本文整理汇总了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;
};
开发者ID:alyiwang,项目名称:WhereHows,代码行数:10,代码来源:metadata-schema.ts

示例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'));
})();
开发者ID:mnahkies,项目名称:DefinitelyTyped,代码行数:43,代码来源:ember__utils-tests.ts

示例3: testTypeOf

function testTypeOf() {
    utils.typeOf(); // $ExpectType string
    utils.typeOf({}); // $ExpectType string
}
开发者ID:mnahkies,项目名称:DefinitelyTyped,代码行数:4,代码来源:utils.ts

示例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'));
})();
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:41,代码来源:ember__utils-tests.ts


注:本文中的@ember/utils.typeOf函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。