本文整理汇总了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 };
}
示例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: [] };
}
示例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)
);
}
示例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);
};