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


TypeScript 8.isPropertySignature方法代码示例

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


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

示例1: checkNode

function checkNode(
  node: ts.Node,
  _ctx: Lint.WalkContext<Options>
): CheckNodeResult {
  const invalidNodes = [];
  if (utils.isInterfaceDeclaration(node)) {
    let prevMemberKind: number | undefined = undefined;
    let prevMemberType: number | undefined = undefined;
    for (const member of node.members) {
      const memberKind = member.kind;
      let memberType = 0;
      // If it is a property declaration we need to check the type too
      if (
        utils.isPropertySignature(member) &&
        member.type &&
        utils.isFunctionTypeNode(member.type)
      ) {
        // We only set memberType for Functions
        memberType = member.type.kind;
      }
      if (
        prevMemberKind !== undefined &&
        (prevMemberKind !== memberKind || prevMemberType !== memberType)
      ) {
        invalidNodes.push(createInvalidNode(member, []));
      }
      prevMemberKind = memberKind;
      prevMemberType = memberType;
    }
  }
  return { invalidNodes };
}
开发者ID:jonaskello,项目名称:tslint-immutable,代码行数:32,代码来源:noMixedInterfaceRule.ts

示例2: checkPropertySignatureAndIndexSignature

function checkPropertySignatureAndIndexSignature(
  node: ts.Node,
  ctx: Lint.WalkContext<Options>
): CheckNodeResult {
  if (
    (utils.isPropertySignature(node) ||
      utils.isIndexSignatureDeclaration(node) ||
      utils.isPropertyDeclaration(node)) &&
    !(
      node.modifiers &&
      node.modifiers.filter(m => m.kind === ts.SyntaxKind.ReadonlyKeyword)
        .length > 0
    )
  ) {
    // Check if ignore-prefix applies
    if (Ignore.shouldIgnorePrefix(node, ctx.options, ctx.sourceFile)) {
      return { invalidNodes: [] };
    }

    const start = utils.isIndexSignatureDeclaration(node)
      ? node.getStart(ctx.sourceFile)
      : node.name.getStart(ctx.sourceFile);

    return {
      invalidNodes: [
        createInvalidNode(node, [new Lint.Replacement(start, 0, "readonly ")])
      ]
    };
  }
  return { invalidNodes: [] };
}
开发者ID:jonaskello,项目名称:tslint-immutable,代码行数:31,代码来源:readonlyKeywordRule.ts

示例3: isVariableLikeDeclaration

export function isVariableLikeDeclaration(
  node: ts.Node
): node is ts.VariableLikeDeclaration {
  return (
    utils.isBindingElement(node) ||
    utils.isEnumMember(node) ||
    utils.isParameterDeclaration(node) ||
    utils.isPropertyAssignment(node) ||
    utils.isPropertyDeclaration(node) ||
    utils.isPropertySignature(node) ||
    utils.isShorthandPropertyAssignment(node) ||
    utils.isVariableDeclaration(node)
  );
}
开发者ID:jonaskello,项目名称:tslint-immutable,代码行数:14,代码来源:typeguard.ts

示例4: return

  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.isPropertySignature方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。