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


TypeScript prop-types.instanceOf函数代码示例

本文整理汇总了TypeScript中prop-types.instanceOf函数的典型用法代码示例。如果您正苦于以下问题:TypeScript instanceOf函数的具体用法?TypeScript instanceOf怎么用?TypeScript instanceOf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了instanceOf函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: constructor

  public constructor() {
    super();

    this.hasSimpleProp("name", true, false)
      .withType(PropTypes.string);

    this.hasSimpleProp("visible", true, true)
      .withDefault(true);

    // this.hasSimpleProp("name", true, true);
    this.hasProp("position", (instance: Object3D,
                              newValue: Vector3 | null,
                              oldProps: IObject3DProps,
                              newProps: IObject3DProps): void => {
      if (newValue === null) {
        instance.position.set(0, 0, 0);
      } else {
        instance.position.copy(newValue);
      }

      if ((newProps.lookAt != null)) {
        instance.lookAt(newProps.lookAt);
      }
    }).withType(PropTypes.instanceOf(Vector3));

    this.hasPropGroup([
      "rotation",
      "quaternion",
      "lookAt",
    ], (instance: Object3D,
        {rotation, quaternion, lookAt}: {
          rotation?: Euler,
          quaternion?: Quaternion,
          lookAt?: Vector3,
        }) => {
      if (lookAt != null) {
        if (isNonProduction) {
          if (quaternion != null) {
            console.warn("An object is being updated with both 'lookAt' and 'quaternion' properties.\n" +
              "Only 'lookAt' will be applied.");
          } else if (rotation != null) {
            console.warn("An object is being updated with both 'lookAt' and 'rotation' properties.\n" +
              "Only 'lookAt' will be applied.");
          }
        }
        instance.lookAt(lookAt);
      } else if ((quaternion != null)) {
        instance.quaternion.copy(quaternion);
      } else if ((rotation != null)) {
        instance.rotation.copy(rotation);
      } else {
        // looks like everything is unset
        instance.quaternion.set(0, 0, 0, 0);
      }
    }).withTypes({
      lookAt: PropTypes.instanceOf(Vector3),
      quaternion: PropTypes.instanceOf(Quaternion),
      rotation: PropTypes.instanceOf(Euler),
    });
  }
开发者ID:sychuginaanna,项目名称:react-three-renderer-fiber,代码行数:60,代码来源:object3DBase.ts

示例2:

/* globals Element */
import * as PropTypes from 'prop-types';

/** @internal */
export const RefType = PropTypes.shape({
  current: PropTypes.instanceOf((typeof Element !== 'undefined') ? Element : Object),
});
开发者ID:MaksimMakarevich,项目名称:devextreme-reactive,代码行数:7,代码来源:ref-type.ts

示例3: emit

import Emitter from '@devexperts/utils/dist/emitter/Emitter';
import * as PropTypes from 'prop-types';

export const EVENT_SCROLABLE = {
	RESIZE: 'EVENT_SCROLABLE:RESIZE',
	SCROLL: 'EVENT_SCROLLABLE:SROLL',
	SCROLLBAR_UPDATE: 'EVENT_SCROLABLE:SCROLLBAR_UPDATE',
};

export class ScrollableInternalEmitter extends Emitter {
	emit(event: any, ...args: any[]) {
		this._emit(event, ...args);
	}
}

export const SCROLLABLE_CONTEXT_EMITTER = '__SCROLLABLE__CONTEXT_EMITTER__';
export const CONTEXT_TYPES = {
	[SCROLLABLE_CONTEXT_EMITTER.toString()]: PropTypes.instanceOf(ScrollableInternalEmitter).isRequired,
	size: PropTypes.shape({
		width: PropTypes.number,
		height: PropTypes.number,
	}),
};
开发者ID:sutarmin,项目名称:dx-platform,代码行数:23,代码来源:Scrollable.const.ts

示例4:

type PropTypesMap = PropTypes.ValidationMap<Props>;

// TS checking
const propTypes: PropTypesMap = {
    any: PropTypes.any,
    array: PropTypes.array.isRequired,
    bool: PropTypes.bool.isRequired,
    element: PropTypes.element.isRequired,
    func: PropTypes.func.isRequired,
    node: PropTypes.node,
    requiredNode: PropTypes.node.isRequired,
    number: PropTypes.number.isRequired,
    object: PropTypes.object.isRequired,
    string: PropTypes.string.isRequired,
    symbol: PropTypes.symbol.isRequired,
    instanceOf: PropTypes.instanceOf(TestClass).isRequired,
    oneOf: PropTypes.oneOf<'a' | 'b' | 'c'>(['a', 'b', 'c']).isRequired,
    oneOfType: PropTypes.oneOfType(arrayOfTypes).isRequired,
    numberOrFalse: PropTypes.oneOfType([PropTypes.oneOf<false>([false]), PropTypes.number]).isRequired,
    // The generic function type (() => any) is assignable to ReactNode because ReactNode extends the empty object type {}
    // Which widens the array literal of validators to just Array<Requireable<() => any>>
    // It's too risky to change ReactNode to exclude {} even though it's invalid, as it's required for children-as-function props to work
    // So we assert the explicit tuple type
    nodeOrRenderFn: PropTypes.oneOfType([PropTypes.node, PropTypes.func] as [PropTypes.Requireable<ReactNode>, PropTypes.Requireable<() => any>]),
    arrayOf: PropTypes.arrayOf(PropTypes.bool.isRequired).isRequired,
    objectOf: PropTypes.objectOf(PropTypes.number.isRequired).isRequired,
    shape: PropTypes.shape(innerProps).isRequired,
    optionalNumber: PropTypes.number,
    customProp: (() => null) as PropTypes.Validator<typeof uniqueType | undefined>
};
开发者ID:Jeremy-F,项目名称:DefinitelyTyped,代码行数:30,代码来源:prop-types-tests.ts


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