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


TypeScript 2.8类代码示例

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


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

示例1: checkNode

function checkNode(
  node: ts.Node,
  _ctx: Lint.WalkContext<Options>
): CheckNodeResult {
  return node &&
    (utils.isForStatement(node) ||
      utils.isForInStatement(node) ||
      utils.isForOfStatement(node) ||
      utils.isWhileStatement(node) ||
      utils.isDoStatement(node))
    ? { invalidNodes: [createInvalidNode(node, [])] }
    : { invalidNodes: [] };
}
开发者ID:jonaskello,项目名称:tslint-immutable,代码行数:13,代码来源:noLoopStatementRule.ts

示例2: checkForStatements

function checkForStatements(
  node: ts.Node,
  ctx: Lint.WalkContext<Options>
): CheckNodeResult {
  if (
    (utils.isForStatement(node) ||
      utils.isForInStatement(node) ||
      utils.isForOfStatement(node)) &&
    node.initializer &&
    utils.isVariableDeclarationList(node.initializer) &&
    Lint.isNodeFlagSet(node.initializer, ts.NodeFlags.Let)
  ) {
    return checkDeclarationList(node.initializer, ctx);
  }
  return { invalidNodes: [] };
}
开发者ID:jonaskello,项目名称:tslint-immutable,代码行数:16,代码来源:noLetRule.ts

示例3: shouldIgnorePrefix

export function shouldIgnorePrefix(
  node: ts.Node,
  options: IgnorePrefixOption,
  sourceFile: ts.SourceFile
): boolean {
  // Check ignore-prefix for VariableLikeDeclaration, TypeAliasDeclaration
  if (options.ignorePrefix) {
    if (
      node &&
      (isVariableLikeDeclaration(node) || utils.isTypeAliasDeclaration(node))
    ) {
      const variableText = node.name.getText(sourceFile);
      // if (
      //   variableText.substr(0, options.ignorePrefix.length) ===
      //   options.ignorePrefix
      // ) {
      //   return true;
      // }
      if (isIgnoredPrefix(variableText, options.ignorePrefix)) {
        return true;
      }
    }
  }
  return false;
}
开发者ID:jonaskello,项目名称:tslint-immutable,代码行数:25,代码来源:ignore.ts

示例4: checkCallExpression

/**
 * No calls to array mutating methods.
 */
function checkCallExpression(
  node: ts.CallExpression,
  ctx: Lint.WalkContext<Options>,
  checker: ts.TypeChecker
): CheckNodeResult {
  if (
    !Ignore.isIgnoredPrefix(
      node.getText(node.getSourceFile()),
      ctx.options.ignorePrefix
    ) &&
    utils.isPropertyAccessExpression(node.expression) &&
    (!(
      ctx.options.ignoreNewArray || ctx.options.ignoreMutationFollowingAccessor
    ) ||
      !isInChainCallAndFollowsNew(node.expression, checker)) &&
    mutatorMethods.some(
      m => m === (node.expression as ts.PropertyAccessExpression).name.text
    )
  ) {
    // Do the type checking as late as possible (as it is expensive).
    const expressionType = checker.getTypeAtLocation(
      getRootAccessExpression(node.expression).expression
    );

    if (isArrayType(expressionType)) {
      return { invalidNodes: [createInvalidNode(node, [])] };
    }
  }
  return { invalidNodes: [] };
}
开发者ID:jonaskello,项目名称:tslint-immutable,代码行数:33,代码来源:noArrayMutationRule.ts

示例5: checkNode

function checkNode(
  node: ts.Node,
  _ctx: Lint.WalkContext<Options>
): CheckNodeResult {
  return utils.isTryStatement(node)
    ? { invalidNodes: [createInvalidNode(node, [])] }
    : { invalidNodes: [] };
}
开发者ID:jonaskello,项目名称:tslint-immutable,代码行数:8,代码来源:noTryRule.ts

示例6: checkNode

function checkNode(
  node: ts.Node,
  _ctx: Lint.WalkContext<Options>
): CheckNodeResult {
  return utils.isDeleteExpression(node)
    ? { invalidNodes: [createInvalidNode(node, [])] }
    : { invalidNodes: [] };
}
开发者ID:jonaskello,项目名称:tslint-immutable,代码行数:8,代码来源:noDeleteRule.ts

示例7: checkNode

function checkNode(
  node: ts.Node,
  _ctx: Lint.WalkContext<Options>
): CheckNodeResult {
  return utils.isClassLikeDeclaration(node)
    ? { invalidNodes: [createInvalidNode(node, [])] }
    : { invalidNodes: [] };
}
开发者ID:jonaskello,项目名称:tslint-immutable,代码行数:8,代码来源:noClassRule.ts

示例8: checkVariableStatement

function checkVariableStatement(
  node: ts.Node,
  ctx: Lint.WalkContext<Options>
): CheckNodeResult {
  if (utils.isVariableStatement(node)) {
    return checkDeclarationList(node.declarationList, ctx);
  }
  return { invalidNodes: [] };
}
开发者ID:jonaskello,项目名称:tslint-immutable,代码行数:9,代码来源:noLetRule.ts

示例9: inConstructor

function inConstructor(nodeIn: ts.Node): boolean {
  let node = nodeIn.parent;
  while (node) {
    if (utils.isConstructorDeclaration(node)) {
      return true;
    }
    node = node.parent;
  }
  return false;
}
开发者ID:jonaskello,项目名称:tslint-immutable,代码行数:10,代码来源:noObjectMutationRule.ts

示例10: checkNode

  return (node: ts.Node, ctx: Lint.WalkContext<Options>) => {
    // Skip checking in functions if ignore-local is set
    if (ctx.options.ignoreLocal && isFunctionLikeDeclaration(node)) {
      // We still need to check the parameters and return type
      const invalidNodes = checkIgnoreLocalFunctionNode(node, ctx, checkNode);
      // Now skip this whole branch
      return { invalidNodes, skipChildren: true };
    }

    // Skip checking in classes/interfaces if ignore-class/ignore-interface is set
    if (
      (ctx.options.ignoreClass && utils.isPropertyDeclaration(node)) ||
      (ctx.options.ignoreInterface && utils.isPropertySignature(node))
    ) {
      // Now skip this whole branch
      return { invalidNodes: [], skipChildren: true };
    }

    // Forward to check node
    return checkNode(node, ctx);
  };
开发者ID:jonaskello,项目名称:tslint-immutable,代码行数:21,代码来源:ignore.ts


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