當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。