本文整理匯總了TypeScript中type-detect.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了default函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
Arr["groupAggregate"] = function (
key: string | Mapper<T, string>,
value: string | Mapper<T, any>,
aggregation: "min" | "max" | "sum" | "avg" | "count")
: X.Dictionary<number> {
// if key is passed as generator function, use it,
// else create generator function that assumes key is a property name.
// If key is null/missing, the string representation of an object is used as the key.
var keyGenerator: Mapper<T, string> = type(key) === "function"
? key as Mapper<T, string>
: (datum) => key
? datum[key.toString()]
: datum.toString();
//Same for value
var valueGenerator: Mapper<T, any> = type(value) === "function"
? value as Mapper<T, any>
: (datum) => value
? datum[value.toString()]
: datum.toString();
var groups: Dictionary<any> = (this as X.Array<T>).groupBy(keyGenerator);
Object.keys(groups)
.forEach(key => {
groups[key] = groups[key][aggregation](valueGenerator)
});
return groups;
}
示例2: createPluginInstance
private createPluginInstance() {
this.log.debug('Initializing plugin');
const pluginDefinition = require(join(this.path, 'server'));
if (!('plugin' in pluginDefinition)) {
throw new Error(`Plugin "${this.name}" does not export "plugin" definition (${this.path}).`);
}
const { plugin: initializer } = pluginDefinition as {
plugin: PluginInitializer<TSetup, TDependenciesSetup>;
};
if (!initializer || typeof initializer !== 'function') {
throw new Error(`Definition of plugin "${this.name}" should be a function (${this.path}).`);
}
const instance = initializer(this.initializerContext);
if (!instance || typeof instance !== 'object') {
throw new Error(
`Initializer for plugin "${
this.manifest.id
}" is expected to return plugin instance, but returned "${typeDetect(instance)}".`
);
}
if (typeof instance.setup !== 'function') {
throw new Error(`Instance of plugin "${this.name}" does not define "setup" function.`);
}
return instance;
}
示例3: handleError
protected handleError(type: string, { message, value }: Record<string, any>, path: string[]) {
switch (type) {
case 'any.required':
case 'duration.base':
return `expected value of type [moment.Duration] but got [${typeDetect(value)}]`;
case 'duration.parse':
return new SchemaTypeError(message, path);
}
}
示例4: handleError
protected handleError(type: string, { reason, value }: Record<string, any>) {
switch (type) {
case 'any.required':
case 'object.base':
return `expected a plain object value, but found [${typeDetect(value)}] instead.`;
case 'object.allowUnknown':
return `definition for this key is missing`;
case 'object.child':
return reason[0];
}
}
示例5: handleError
protected handleError(type: string, { limit, value }: Record<string, any>) {
switch (type) {
case 'any.required':
case 'number.base':
return `expected value of type [number] but got [${typeDetect(value)}]`;
case 'number.min':
return `Value is [${value}] but it must be equal to or greater than [${limit}].`;
case 'number.max':
return `Value is [${value}] but it must be equal to or lower than [${limit}].`;
}
}
示例6: handleError
protected handleError(type: string, { value, scheme }: Record<string, unknown>) {
switch (type) {
case 'any.required':
case 'string.base':
return `expected value of type [string] but got [${typeDetect(value)}].`;
case 'string.uriCustomScheme':
return `expected URI with scheme [${scheme}] but but got [${value}].`;
case 'string.uri':
return `value is [${value}] but it must be a valid URI (see RFC 3986).`;
}
}
示例7: handleError
protected handleError(type: string, { limit, value }: Record<string, any>) {
switch (type) {
case 'any.required':
case 'string.base':
return `expected value of type [string] but got [${typeDetect(value)}]`;
case 'string.min':
return `value is [${value}] but it must have a minimum length of [${limit}].`;
case 'string.max':
return `value is [${value}] but it must have a maximum length of [${limit}].`;
}
}
示例8:
Arr["union"] = function <T>(array: T[]): ArrayX<T> {
var arr = [];
var self = (this as any[]);
for (var i = 0; i < self.length; i++)
arr.push(self[i]);
if (type(array) === "Array")
for (var k = 0; k < array.length; k++)
arr.push(array[k]);
return new ArrayX<T>(...arr);
}
示例9: handleError
protected handleError(type: string, { limit, reason, value }: Record<string, any>) {
switch (type) {
case 'any.required':
case 'array.base':
return `expected value of type [array] but got [${typeDetect(value)}]`;
case 'array.min':
return `array size is [${value.length}], but cannot be smaller than [${limit}]`;
case 'array.max':
return `array size is [${value.length}], but cannot be greater than [${limit}]`;
case 'array.includesOne':
return reason[0];
}
}
示例10: if
var arr: T[] = clone(this).sort(function (a, b) {
var objA = func ? func(a) : a;
var objB = func ? func(b) : b;
var comparison = null;
if (objA && objB) {
if (type(objA) === "number")
comparison = objA - objB;
else if (type(objA) === "date")
comparison = objA.getTime() - objB.getTime();
else
comparison = objA.toString().localeCompare(objB.toString());
}
else {
if (!objA && !objB)
comparison = 0;
else if (!objA)
comparison = -1;
else
comparison = 1;
}
return comparison;
});