How to use the typescript.TypeFlags function in typescript

To help you get started, we’ve selected a few typescript examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MichaReiser / speedy.js / packages / compiler / src / code-generation / value / undefined.ts View on Github external
castImplicit(type: ts.Type, context: CodeGenerationContext): Value | any {
        if (type.flags & ts.TypeFlags.BooleanLike) {
            return Primitive.false(context, type);
        }

        if (type.flags & ts.TypeFlags.IntLike) {
            return new Primitive(llvm.ConstantInt.get(context.llvmContext, 0), type);
        }

        if (type.flags & ts.TypeFlags.NumberLike) {
            return new Primitive(llvm.ConstantFP.getNaN(llvm.Type.getDoubleTy(context.llvmContext)), type);
        }

        // cast pointer
        if (type.flags & ts.TypeFlags.Object || isMaybeObjectType(type) || type.flags & ts.TypeFlags.Undefined) {
            return new Undefined(context.builder.createBitCast(this.generateIR(context), context.toLLVMType(type)));
        }

        return undefined;
    }
github palantir / tslint / src / rules / strictComparisonsRule.ts View on Github external
function getKind(type: ts.Type): TypeKind {
    // tslint:disable:no-bitwise
    if (is(ts.TypeFlags.String | ts.TypeFlags.StringLiteral)) {
        return TypeKind.String;
    } else if (is(ts.TypeFlags.Number | ts.TypeFlags.NumberLiteral)) {
        return TypeKind.Number;
    } else if (is(ts.TypeFlags.BooleanLike)) {
        return TypeKind.Boolean;
    } else if (is(ts.TypeFlags.Null)) {
        return TypeKind.Null;
    } else if (is(ts.TypeFlags.Undefined)) {
        return TypeKind.Undefined;
    } else if (is(ts.TypeFlags.Any)) {
        return TypeKind.Any;
    } else {
        return TypeKind.Object;
    }
    // tslint:enable:no-bitwise

    function is(flags: ts.TypeFlags) {
        return isTypeFlagSet(type, flags);
    }
}
github bfwg / angular-spring-starter / frontend / node_modules / tslint / lib / rules / strictTypePredicatesRule.js View on Github external
switch (kind) {
        case "undefined":
            return flagPredicate(undefinedFlags);
        case "boolean":
            return flagPredicate(ts.TypeFlags.BooleanLike);
        case "number":
            return flagPredicate(ts.TypeFlags.NumberLike);
        case "string":
            return flagPredicate(ts.TypeFlags.StringLike);
        case "symbol":
            return flagPredicate(ts.TypeFlags.ESSymbol);
        case "function":
            return isFunction;
        case "object":
            // It's an object if it's not any of the above.
            var allFlags_1 = ts.TypeFlags.Undefined | ts.TypeFlags.Void | ts.TypeFlags.BooleanLike |
                ts.TypeFlags.NumberLike | ts.TypeFlags.StringLike | ts.TypeFlags.ESSymbol;
            return function (type) { return !Lint.isTypeFlagSet(type, allFlags_1) && !isFunction(type); };
        default:
            return undefined;
    }
}
function flagPredicate(testedFlag) {
github fossasia / susper.com / node_modules / tslint / lib / rules / strictBooleanExpressionsRule.js View on Github external
function getTypeFailure(type, options) {
    if (isUnionType(type)) {
        return handleUnion(type, options);
    }
    var kind = getKind(type);
    var failure = failureForKind(kind, /*isInUnion*/ false, options);
    if (failure !== undefined) {
        return failure;
    }
    switch (triState(kind)) {
        case true:
            // Allow 'any'. Allow 'true' itself, but not any other always-truthy type.
            // tslint:disable-next-line no-bitwise
            return tsutils_1.isTypeFlagSet(type, ts.TypeFlags.Any | ts.TypeFlags.BooleanLiteral)
                ? undefined
                : 0 /* AlwaysTruthy */;
        case false:
            // Allow 'false' itself, but not any other always-falsy type
            return tsutils_1.isTypeFlagSet(type, ts.TypeFlags.BooleanLiteral)
                ? undefined
                : 1 /* AlwaysFalsy */;
        case undefined:
            return undefined;
    }
}
function isBooleanUndefined(type) {
github ts-llvm / ts-llvm / src / types.ts View on Github external
}

  if (isString(type)) {
    return getStringType(context);
  }

  if (isObject(type)) {
    // TODO: Pass correct isOpaque parameter.
    return getStructType(type, false, generator).getPointerTo();
  }

  if (type.flags & ts.TypeFlags.Void) {
    return llvm.Type.getVoidTy(context);
  }

  if (type.flags & ts.TypeFlags.Any) {
    return error("'any' type is not supported");
  }

  return error(`Unhandled ts.Type '${checker.typeToString(type)}'`);
}
github fossasia / susper.com / node_modules / tslint / lib / rules / strictTypePredicatesRule.js View on Github external
function getTypePredicateForKind(kind) {
    switch (kind) {
        case "undefined":
            return flagPredicate(undefinedFlags);
        case "boolean":
            return flagPredicate(ts.TypeFlags.BooleanLike);
        case "number":
            return flagPredicate(ts.TypeFlags.NumberLike);
        case "string":
            return flagPredicate(ts.TypeFlags.StringLike);
        case "symbol":
            return flagPredicate(ts.TypeFlags.ESSymbol);
        case "function":
            return isFunction;
        case "object":
            // It's an object if it's not any of the above.
            var allFlags_1 = ts.TypeFlags.Undefined |
                ts.TypeFlags.Void |
                ts.TypeFlags.BooleanLike |
                ts.TypeFlags.NumberLike |
                ts.TypeFlags.StringLike |
                ts.TypeFlags.ESSymbol;
            return function (type) { return !tsutils_1.isTypeFlagSet(type, allFlags_1) && !isFunction(type); };
        default:
            return undefined;
    }
github nativescript-rtl / ui / node_modules / tslint / lib / rules / noVoidExpressionRule.js View on Github external
return ts.forEachChild(sourceFile, function cb(node) {
        if (isPossiblyVoidExpression(node) &&
            !isParentAllowedVoid(node) &&
            tsutils_1.isTypeFlagSet(checker.getTypeAtLocation(node), ts.TypeFlags.Void)) {
            ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
        }
        return ts.forEachChild(node, cb);
    });
    function isParentAllowedVoid(node) {
github daviddbarrero / Ionic-4-firebase / node_modules / @angular / compiler-cli / src / diagnostics / typescript_symbols.js View on Github external
(function (type) {
        return !!(type.flags & ts.TypeFlags.Object &&
            type.objectFlags & ts.ObjectFlags.Reference);
    }) :
    (function (type) { return !!(type.flags & ts.TypeFlags.Reference); });
github VadimDez / ng2-pdf-viewer / build / lib / @angular / compiler-cli / src / diagnostics / typescript_symbols.js View on Github external
    (function (type) { return !!(type.flags & ts.TypeFlags.Reference); });
function getSymbolQuery(program, checker, source, fetchPipes) {
github bfwg / angular-spring-starter / frontend / node_modules / tslint / lib / rules / noInferredEmptyObjectTypeRule.js View on Github external
NoInferredEmptyObjectTypeRule.prototype.checkNewExpression = function (node) {
        var _this = this;
        if (node.typeArguments === undefined) {
            var objType = this.checker.getTypeAtLocation(node);
            if (utils_1.isTypeFlagSet(objType, ts.TypeFlags.Object) && objType.typeArguments !== undefined) {
                var typeArgs = objType.typeArguments;
                if (typeArgs.some(function (a) { return _this.isEmptyObjectInterface(a); })) {
                    this.addFailureAtNode(node, Rule.EMPTY_INTERFACE_INSTANCE);
                }
            }
        }
    };
    NoInferredEmptyObjectTypeRule.prototype.checkCallExpression = function (node) {