本文整理汇总了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),
});
}
示例2:
/* globals Element */
import * as PropTypes from 'prop-types';
/** @internal */
export const RefType = PropTypes.shape({
current: PropTypes.instanceOf((typeof Element !== 'undefined') ? Element : Object),
});
示例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,
}),
};
示例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>
};