本文整理匯總了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>
};