本文整理匯總了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);
};