lib/rules/no-inferrable-types.js
function isInferrable(node, init) {
            if (node.type !== "TSTypeAnnotation" || !node.typeAnnotation) {
                return false;
            }

            if (!init) {
                return false;
            }

            const annotation = node.typeAnnotation;

            if (annotation.type === "TSStringKeyword") {
                return (
                    (init.type === "Literal" &&
                        typeof init.value === "string") ||
                    (init.type === "TemplateElement" &&
                        (!init.expressions || init.expressions.length === 0))
                );
            }

            if (annotation.type === "TSBooleanKeyword") {
                return init.type === "Literal";
            }

            if (annotation.type === "TSNumberKeyword") {
                // Infinity is special
                if (
                    (init.type === "UnaryExpression" &&
                        init.operator === "-" &&
                        init.argument.type === "Identifier" &&
                        init.argument.name === "Infinity") ||
                    (init.type === "Identifier" && init.name === "Infinity")
                ) {
                    return true;
                }

                return (
                    init.type === "Literal" && typeof init.value === "number"
                );
            }

            return false;
        }
function isInferrable(node, init) {
            if (node.type !== "TSTypeAnnotation" || !node.typeAnnotation) {
                return false;
            }

            if (!init) {
                return false;
            }

            const annotation = node.typeAnnotation;

            if (annotation.type === "TSStringKeyword") {
                return (
                    (init.type === "Literal" &&
                        typeof init.value === "string") ||
                    (init.type === "TemplateElement" &&
                        (!init.expressions || init.expressions.length === 0))
                );
            }

            if (annotation.type === "TSBooleanKeyword") {
                return init.type === "Literal";
            }

            if (annotation.type === "TSNumberKeyword") {
                // Infinity is special
                if (
                    (init.type === "UnaryExpression" &&
                        init.operator === "-" &&
                        init.argument.type === "Identifier" &&
                        init.argument.name === "Infinity") ||
                    (init.type === "Identifier" && init.name === "Infinity")
                ) {
                    return true;
                }

                return (
                    init.type === "Literal" && typeof init.value === "number"
                );
            }

            return false;
        }
function isInferrable ( node , init ) { if ( node . type !== "TSTypeAnnotation" || ! node . typeAnnotation ) { return false ; } if ( ! init ) { return false ; } const annotation = node . typeAnnotation ; if ( annotation . type === "TSStringKeyword" ) { return ( ( init . type === "Literal" && typeof init . value === "string" ) || ( init . type === "TemplateElement" && ( ! init . expressions || init . expressions . length === 0 ) ) ) ; } if ( annotation . type === "TSBooleanKeyword" ) { return init . type === "Literal" ; } if ( annotation . type === "TSNumberKeyword" ) { // Infinity is special if ( ( init . type === "UnaryExpression" && init . operator === "-" && init . argument . type === "Identifier" && init . argument . name === "Infinity" ) || ( init . type === "Identifier" && init . name === "Infinity" ) ) { return true ; } return ( init . type === "Literal" && typeof init . value === "number" ) ; } return false ; }
Returns whether a node has an inferrable value or not
@param {ASTNode} node the node to check
@param {ASTNode} init the initializer
@returns {boolean} whether the node has an inferrable type
Returns whether a node has an inferrable value or not