本文整理汇总了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: [] };
}
示例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: [] };
}
示例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;
}
示例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: [] };
}
示例5: checkNode
function checkNode(
node: ts.Node,
_ctx: Lint.WalkContext<Options>
): CheckNodeResult {
return utils.isTryStatement(node)
? { invalidNodes: [createInvalidNode(node, [])] }
: { invalidNodes: [] };
}
示例6: checkNode
function checkNode(
node: ts.Node,
_ctx: Lint.WalkContext<Options>
): CheckNodeResult {
return utils.isDeleteExpression(node)
? { invalidNodes: [createInvalidNode(node, [])] }
: { invalidNodes: [] };
}
示例7: checkNode
function checkNode(
node: ts.Node,
_ctx: Lint.WalkContext<Options>
): CheckNodeResult {
return utils.isClassLikeDeclaration(node)
? { invalidNodes: [createInvalidNode(node, [])] }
: { invalidNodes: [] };
}
示例8: checkVariableStatement
function checkVariableStatement(
node: ts.Node,
ctx: Lint.WalkContext<Options>
): CheckNodeResult {
if (utils.isVariableStatement(node)) {
return checkDeclarationList(node.declarationList, ctx);
}
return { invalidNodes: [] };
}
示例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;
}
示例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);
};