本文整理汇总了TypeScript中util.deprecate函数的典型用法代码示例。如果您正苦于以下问题:TypeScript deprecate函数的具体用法?TypeScript deprecate怎么用?TypeScript deprecate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了deprecate函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: bar
/////////////////////////////////////////////////////
/// util tests : https://nodejs.org/api/util.html ///
/////////////////////////////////////////////////////
namespace util_tests {
{
// Old and new util.inspect APIs
util.inspect(["This is nice"], false, 5);
util.inspect(["This is nice"], false, null);
util.inspect(["This is nice"], { colors: true, depth: 5, customInspect: false });
util.inspect(["This is nice"], { colors: true, depth: null, customInspect: false });
// util.deprecate
const foo = () => {};
// $ExpectType () => void
util.deprecate(foo, 'foo() is deprecated, use bar() instead');
// $ExpectType <T extends Function>(fn: T, message: string) => T
util.deprecate(util.deprecate, 'deprecate() is deprecated, use bar() instead');
}
}
////////////////////////////////////////////////////
/// Stream tests : http://nodejs.org/api/stream.html
////////////////////////////////////////////////////
// http://nodejs.org/api/stream.html#stream_readable_pipe_destination_options
function stream_readable_pipe_test() {
var r = fs.createReadStream('file.txt');
var z = zlib.createGzip();
var w = fs.createWriteStream('file.txt.gz');
r.pipe(z).pipe(w);
示例2: deprecate
import { map } from 'starry.map'
import { deprecate } from 'util'
export = deprecate(function asyncOperation(operation, iterable, asyncAction) {
return operation(map(iterable, asyncAction))
}, 'Use starry.map instead')
示例3: convertResult
import { deprecate } from 'util';
import DataEntity, { DataInput } from '../data-entity';
import { isPlainObject, getFirst, castArray, isString } from '../../utils';
/**
* Convert legacy processor results into DataEntities if possible.
* But in order to be more backwards compatible legacy modules
* can return an array of buffers or strings.
*/
export function convertResult(input: DataInput[]|Buffer[]|string[]): DataEntity[] {
if (input == null) return [];
if (Array.isArray(input) && input.length === 0) return [];
if (DataEntity.isDataEntityArray(input)) return input;
if (DataEntity.isDataEntity(input)) return [input];
const first = getFirst<object|string|Buffer>(input);
if (first == null) return [];
// @ts-ignore
if (Array.isArray(first)) return input;
if (Buffer.isBuffer(first) || isString(first)) return deprecateType(input);
if (isPlainObject(first)) return DataEntity.makeArray(input);
throw new Error('Invalid return type for processor');
}
const deprecateType = deprecate((result: any): DataEntity[] => {
return castArray<DataEntity>(result);
}, 'Legacy processors should return an array of Objects or DataEntities');
示例4: deprecate
import dllConf from './config/dll.conf'
import prodConf from './config/prod.conf'
import { appPath } from './util'
import { bindDevLogger, bindProdLogger, bindDllLogger, printBuildError } from './util/logHelper'
import { BuildConfig } from './util/types'
const customizeChain = (chain, config) => {
if (config.webpackChain instanceof Function) {
config.webpackChain(chain, webpack)
}
}
const deprecatedCustomizeConfig = deprecate((baseConfig, customConfig) => {
if (customConfig instanceof Function) {
return customConfig(baseConfig, webpack)
} else if (customConfig instanceof Object) {
return webpackMerge({}, baseConfig, customConfig)
}
}, chalk.yellow(`h5.webpack配置项即将停止支持,请尽快迁移到新配置项。新配置项文档:https://nervjs.github.io/taro/docs/config-detail.html#h5`))
const buildDll = async (config: BuildConfig): Promise<any> => {
if (config.enableDll === false) return Promise.resolve()
return new Promise((resolve, reject) => {
const webpackChain = dllConf(config)
const webpackConfig = webpackChain.toConfig()
const compiler = webpack(webpackConfig)
bindDllLogger(compiler)
compiler.run((err) => {
if (err) {
printBuildError(err)
示例5: function
}
return this
}
const multi = Pipeline.prototype.multi
Pipeline.prototype.multi = function () {
this._transactions += 1
return multi.apply(this, arguments)
}
const execBuffer = Pipeline.prototype.execBuffer
const exec = Pipeline.prototype.exec
Pipeline.prototype.execBuffer = deprecate(function () {
if (this._transactions > 0) {
this._transactions -= 1
}
return execBuffer.apply(this, arguments)
}, 'Pipeline#execBuffer: Use Pipeline#exec instead')
Pipeline.prototype.exec = function (callback: CallbackFunction) {
if (this._transactions > 0) {
this._transactions -= 1
return (this.options.dropBufferSupport ? exec : execBuffer).apply(this, arguments)
}
if (!this.nodeifiedPromise) {
this.nodeifiedPromise = true
asCallback(this.promise, callback)
}
if (!this._queue.length) {
this.resolve([])
}