{"action":"closed","issue":{"url":"https://api.github.com/repos/palantir/tslint/issues/4162","repository_url":"https://api.github.com/repos/palantir/tslint","labels_url":"https://api.github.com/repos/palantir/tslint/issues/4162/labels{/name}","comments_url":"https://api.github.com/repos/palantir/tslint/issues/4162/comments","events_url":"https://api.github.com/repos/palantir/tslint/issues/4162/events","html_url":"https://github.com/palantir/tslint/issues/4162","id":358793837,"node_id":"MDU6SXNzdWUzNTg3OTM4Mzc=","number":4162,"title":"Unsafe use of expression of type 'any' fired for calls using JSON","user":{"login":"dudewad","id":3123975,"node_id":"MDQ6VXNlcjMxMjM5NzU=","avatar_url":"https://avatars2.githubusercontent.com/u/3123975?v=4","gravatar_id":"","url":"https://api.github.com/users/dudewad","html_url":"https://github.com/dudewad","followers_url":"https://api.github.com/users/dudewad/followers","following_url":"https://api.github.com/users/dudewad/following{/other_user}","gists_url":"https://api.github.com/users/dudewad/gists{/gist_id}","starred_url":"https://api.github.com/users/dudewad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dudewad/subscriptions","organizations_url":"https://api.github.com/users/dudewad/orgs","repos_url":"https://api.github.com/users/dudewad/repos","events_url":"https://api.github.com/users/dudewad/events{/privacy}","received_events_url":"https://api.github.com/users/dudewad/received_events","type":"User","site_admin":false},"labels":[{"id":49399916,"node_id":"MDU6TGFiZWw0OTM5OTkxNg==","url":"https://api.github.com/repos/palantir/tslint/labels/Resolution:%20Duplicate","name":"Resolution: Duplicate","color":"cccccc","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-09-10T21:03:35Z","updated_at":"2018-11-05T16:43:29Z","closed_at":"2018-11-05T16:43:29Z","author_association":"NONE","body":"### Bug Report\r\n\r\n- __TSLint version__: 5.9.1\r\n- __TypeScript version__: 2.7.2\r\n- __Running TSLint via__: Node.js API\r\n\r\n#### TypeScript code being linted\r\n\r\n```ts\r\nconst storageId = `user-${id}`;\r\nconst rawData: string = localStorage.getItem(storageId);\r\n\r\nconst parsedData: { timestamp: string, results: string[]} = JSON.parse(rawData);\r\n```\r\n\r\nwith `tslint.json` configuration:\r\n\r\n```json\r\n{\r\n  \"extends\": [\r\n    \"tslint-eslint-rules\"\r\n  ],\r\n  \"rulesDirectory\": [\r\n    \"node_modules/codelyzer\"\r\n  ],\r\n  \"defaultSeverity\": \"warn\",\r\n  \"rules\": {\r\n    \"adjacent-overload-signatures\": true,\r\n    \"align\": [\r\n      true,\r\n      \"members\",\r\n      \"parameters\",\r\n      \"statements\"\r\n    ],\r\n    \"array-type\": [\r\n      true,\r\n      \"array-simple\"\r\n    ],\r\n    \"arrow-parens\": [true, \"ban-single-arg-parens\"],\r\n    \"arrow-return-shorthand\": true,\r\n    \"await-promise\": true,\r\n    \"ban\": false,\r\n    \"ban-types\": [\r\n      true, [\r\n        \"Object\",\r\n        \"Avoid using the `Object` type. Did you mean `object`?\"\r\n      ],\r\n      [\r\n        \"Function\",\r\n        \"Avoid using the `Function` type. Prefer a specific function type, like `() => void`.\"\r\n      ],\r\n      [\r\n        \"Boolean\",\r\n        \"Avoid using the `Boolean` type. Did you mean `boolean`?\"\r\n      ],\r\n      [\r\n        \"Number\",\r\n        \"Avoid using the `Number` type. Did you mean `number`?\"\r\n      ],\r\n      [\r\n        \"String\",\r\n        \"Avoid using the `String` type. Did you mean `string`?\"\r\n      ],\r\n      [\r\n        \"Symbol\",\r\n        \"Avoid using the `Symbol` type. Did you mean `symbol`?\"\r\n      ]\r\n    ],\r\n    \"binary-expression-operand-order\": true,\r\n    \"callable-types\": true,\r\n    \"class-name\": true,\r\n    \"comment-format\": [\r\n      true,\r\n      \"check-space\"\r\n    ],\r\n    \"completed-docs\": [\r\n      true,\r\n      {\r\n        \"functions\": {\r\n          \"visibilities\": [\"exported\"]\r\n        },\r\n        \"methods\": {\r\n          \"locations\": [\"all\"],\r\n          \"privacies\": [\"public\", \"protected\"]\r\n        }\r\n      }\r\n    ],\r\n    \"curly\": [true, \"ignore-same-line\"],\r\n    \"cyclomatic-complexity\": [true],\r\n    \"encoding\": true,\r\n    \"eofline\": true,\r\n    \"file-header\": [\r\n      false\r\n    ],\r\n    \"forin\": true,\r\n    \"import-blacklist\": [true, \"rxjs\"],\r\n    \"import-spacing\": true,\r\n    \"indent\": [\r\n      true,\r\n      \"spaces\",\r\n      2\r\n    ],\r\n    \"interface-name\": [\r\n      true,\r\n      \"never-prefix\"\r\n    ],\r\n    \"interface-over-type-literal\": true,\r\n    \"jsdoc-format\": true,\r\n    \"label-position\": true,\r\n    \"linebreak-style\": [\r\n      false,\r\n      \"LF\"\r\n    ],\r\n    \"match-default-export-name\": [true],\r\n    \"max-classes-per-file\": [\r\n      true,\r\n      1\r\n    ],\r\n    \"max-file-line-count\": [\r\n      true,\r\n      499\r\n    ],\r\n    \"max-line-length\": [false], // using ter-max-len because it has more options\r\n    \"member-access\": [\r\n      true,\r\n      \"check-accessor\",\r\n      \"check-constructor\"\r\n    ],\r\n    \"member-ordering\": [\r\n      true,\r\n      \"static-before-instance\",\r\n      \"variables-before-functions\"\r\n    ],\r\n    \"new-parens\": true,\r\n    \"newline-before-return\": true,\r\n    \"no-angle-bracket-type-assertion\": true,\r\n    \"no-any\": true,\r\n    \"no-arg\": true,\r\n    \"no-bitwise\": true,\r\n    \"no-boolean-literal-compare\": false,\r\n    \"no-conditional-assignment\": true,\r\n    \"no-consecutive-blank-lines\": [true],\r\n    \"no-console\": [\r\n      true,\r\n      \"debug\",\r\n      \"info\",\r\n      \"log\",\r\n      \"time\",\r\n      \"timeEnd\",\r\n      \"trace\"\r\n    ],\r\n    \"no-construct\": true,\r\n    \"no-debugger\": true,\r\n    \"no-default-export\": true,\r\n    \"no-duplicate-super\": true,\r\n    \"no-duplicate-variable\": [true, \"check-parameters\"],\r\n    \"no-empty\": true,\r\n    \"no-empty-interface\": true,\r\n    \"no-eval\": true,\r\n    \"no-floating-promises\": [false],\r\n    \"no-for-in-array\": true,\r\n    \"no-import-side-effect\": [false],\r\n    \"no-inferrable-types\": [true, \"ignore-params\"],\r\n    \"no-inferred-empty-object-type\": true,\r\n    \"no-internal-module\": true,\r\n    \"no-invalid-template-strings\": true,\r\n    \"no-invalid-this\": false,\r\n    \"no-irregular-whitespace\": true,\r\n    \"no-magic-numbers\": [true, 0, 1, -1, 10],\r\n    \"no-mergeable-namespace\": true,\r\n    \"no-misused-new\": true,\r\n    \"no-namespace\": true,\r\n    \"no-non-null-assertion\": true,\r\n    \"no-null-keyword\": true,\r\n    \"no-object-literal-type-assertion\": true,\r\n    \"no-parameter-properties\": false,\r\n    \"no-reference\": true,\r\n    \"no-reference-import\": true,\r\n    \"no-require-imports\": true,\r\n    \"no-shadowed-variable\": true,\r\n    \"no-sparse-arrays\": true,\r\n    \"no-string-literal\": false, // noImplicitAny compiler option prevents issues caused by this\r\n    \"no-string-throw\": true,\r\n    \"no-switch-case-fall-through\": true,\r\n    \"no-trailing-whitespace\": true,\r\n    \"no-unbound-method\": [true, \"ignore-static\"],\r\n    \"no-unnecessary-callback-wrapper\": true,\r\n    \"no-unnecessary-initializer\": true,\r\n    \"no-unnecessary-qualifier\": true,\r\n    \"no-unsafe-any\": true,\r\n    \"no-unsafe-finally\": true,\r\n    \"no-unused-expression\": true,\r\n    \"no-use-before-declare\": true,\r\n    \"no-var-keyword\": true,\r\n    \"no-var-requires\": true,\r\n    \"no-void-expression\": [\r\n      true,\r\n      \"ignore-arrow-function-shorthand\"\r\n    ],\r\n    \"number-literal-format\": true,\r\n    \"object-literal-key-quotes\": [\r\n      true,\r\n      \"consistent-as-needed\"\r\n    ],\r\n    \"object-literal-shorthand\": true,\r\n    \"object-literal-sort-keys\": false,\r\n    \"one-line\": [\r\n      true,\r\n      \"check-catch\",\r\n      \"check-else\",\r\n      \"check-finally\",\r\n      \"check-open-brace\",\r\n      \"check-whitespace\"\r\n    ],\r\n    \"one-variable-per-declaration\": [\r\n      true,\r\n      \"ignore-for-loop\"\r\n    ],\r\n    \"only-arrow-functions\": [\r\n      true,\r\n      \"allow-declarations\",\r\n      \"allow-named-functions\"\r\n    ],\r\n    \"ordered-imports\": [\r\n      true,\r\n      {\r\n        \"import-sources-order\": \"case-insensitive\",\r\n        \"named-imports-order\": \"case-insensitive\"\r\n      }\r\n    ],\r\n    \"prefer-conditional-expression\": true,\r\n    \"prefer-const\": true,\r\n    \"prefer-for-of\": true,\r\n    \"prefer-function-over-method\": [\r\n      false\r\n    ],\r\n    \"prefer-method-signature\": true,\r\n    \"prefer-object-spread\": true,\r\n    \"prefer-switch\": true,\r\n    \"prefer-template\": [\r\n      true,\r\n      \"allow-single-concat\"\r\n    ],\r\n    \"promise-function-async\": true,\r\n    \"quotemark\": [\r\n      true,\r\n      \"single\",\r\n      \"avoid-escape\"\r\n    ],\r\n    \"radix\": true,\r\n    \"restrict-plus-operands\": true,\r\n    \"return-undefined\": false,\r\n    \"semicolon\": [\r\n      true,\r\n      \"always\"\r\n    ],\r\n    \"space-before-function-paren\": [\r\n      true,\r\n      {\r\n        \"anonymous\": \"never\",\r\n        \"asyncArrow\": \"always\",\r\n        \"constructor\": \"never\",\r\n        \"method\": \"never\",\r\n        \"named\": \"never\"\r\n      }\r\n    ],\r\n    \"strict-boolean-expressions\": false,\r\n    \"strict-type-predicates\": true,\r\n    \"switch-default\": false,\r\n    \"switch-final-break\": [true, \"always\"],\r\n    \"trailing-comma\": [\r\n      true,\r\n      {\r\n        \"multiline\": \"always\",\r\n        \"singleline\": \"never\"\r\n      }\r\n    ],\r\n    \"triple-equals\": [\r\n      true,\r\n      \"allow-null-check\"\r\n    ],\r\n    \"typedef\": [false],\r\n    \"typedef-whitespace\": [\r\n      true,\r\n      {\r\n        \"call-signature\": \"nospace\",\r\n        \"index-signature\": \"nospace\",\r\n        \"parameter\": \"nospace\",\r\n        \"property-declaration\": \"nospace\",\r\n        \"variable-declaration\": \"nospace\"\r\n      },\r\n      {\r\n        \"call-signature\": \"onespace\",\r\n        \"index-signature\": \"onespace\",\r\n        \"parameter\": \"onespace\",\r\n        \"property-declaration\": \"onespace\",\r\n        \"variable-declaration\": \"onespace\"\r\n      }\r\n    ],\r\n    \"typeof-compare\": true,\r\n    \"unified-signatures\": true,\r\n    \"use-default-type-parameter\": true,\r\n    \"use-isnan\": true,\r\n    \"variable-name\": [\r\n      true,\r\n      \"allow-leading-underscore\",\r\n      \"allow-pascal-case\",\r\n      \"ban-keywords\",\r\n      \"check-format\"\r\n    ],\r\n    \"whitespace\": [\r\n      true,\r\n      \"check-branch\",\r\n      \"check-decl\",\r\n      \"check-operator\",\r\n      \"check-module\",\r\n      \"check-separator\",\r\n      \"check-type\",\r\n      \"check-preblock\"\r\n    ],\r\n\r\n    // ===== Codelyzer =====\r\n    \"angular-whitespace\": [true, \"check-interpolation\"],  // todo:mm: add check-pipe options when fixed: https://github.com/mgechev/codelyzer/issues/346\r\n    \"banana-in-box\": true,\r\n    \"component-class-suffix\": true,\r\n    \"component-selector\": [true, \"element\", \"mc\", \"kebab-case\"],\r\n    \"directive-class-suffix\": true,\r\n    \"directive-selector\": [true, \"attribute\", \"mc\", \"camelCase\"],\r\n    \"invoke-injectable\": true,\r\n    \"no-access-missing-member\": true,\r\n    \"no-attribute-parameter-decorator\": true,\r\n    \"no-forward-ref\": true,\r\n    \"no-input-rename\": true,\r\n    \"no-output-rename\": true,\r\n    \"pipe-naming\": [true, \"camelCase\", \"mc\"],\r\n    \"no-unused-css\": true,\r\n    \"pipe-impure\": true,\r\n    \"template-to-ng-template\": true,\r\n    \"templates-no-negated-async\": true,\r\n    \"templates-use-public\": true,\r\n    \"use-host-property-decorator\": true,\r\n    \"use-input-property-decorator\": true,\r\n    \"use-life-cycle-interface\": true,\r\n    \"use-output-property-decorator\": true,\r\n    \"use-pipe-transform-interface\": true,\r\n    \"use-view-encapsulation\": true,\r\n\r\n    // ===== tslint-eslint-rules =====\r\n    \"no-constant-condition\": true, // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/noConstantConditionRule.md\r\n    \"no-control-regex\": true, // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/noControlRegexRule.md\r\n    \"no-duplicate-case\": true, // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/noDuplicateCaseRule.md\r\n    \"no-empty-character-class\": true, // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/noEmptyCharacterClassRule.md\r\n    \"no-ex-assign\": true, // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/noExAssignRule.md\r\n    \"no-extra-boolean-cast\": true, // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/noExtraBooleanCastRule.md\r\n    \"no-extra-semi\": true, // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/noExtraSemiRule.md\r\n    \"no-inner-declarations\": [true, \"functions\"], // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/noInnerDeclarationsRule.md\r\n    \"no-invalid-regexp\": true, // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/noInvalidRegexpRule.md\r\n    \"no-regex-spaces\": true, // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/noRegexSpacesRule.md\r\n    \"no-unexpected-multiline\": true, // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/noUnexpectedMultilineRule.md\r\n    \"valid-jsdoc\": [true, { // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/validJsdocRule.md\r\n      \"matchDescription\": \".+\",\r\n      \"prefer\": {\r\n        \"return\": \"returns\"\r\n      },\r\n      \"requireParamType\": false,\r\n      \"requireParamDescription\": true,\r\n      \"requireReturn\": false,\r\n      \"requireReturnType\": false,\r\n      \"requireReturnDescription\": true\r\n    }],\r\n    \"valid-typeof\": true, // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/validTypeofRule.md\r\n    \"no-multi-spaces\": true, // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/noMultiSpacesRule.md\r\n    \"handle-callback-err\": [true, \"error\"], // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/handleCallbackErrRule.md\r\n    \"array-bracket-spacing\": [ // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/arrayBracketSpacingRule.md\r\n      true,\r\n      \"never\",\r\n      {\r\n        \"arraysInArrays\": true\r\n      }\r\n    ],\r\n    \"block-spacing\": [true, \"always\"], // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/blockSpacingRule.md\r\n    // \"brace-style\": [true, \"1tbs\"], // using TSlint's instead // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/braceStyleRule.md\r\n    // \"ter-indent\": [true, 2], // using TSLint's instead // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/terIndentRule.md\r\n    \"ter-max-len\": [ // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/terMaxLenRule.md\r\n      true,\r\n      {\r\n        \"code\": 80,\r\n        \"tabWidth\": 4,\r\n        \"ignoreUrls\": true,\r\n        // ignore the last line of multiline imports, e.g: } from 'some-module';\r\n        // also ignores test cases with long descriptions, e.g. it('does something long') // although this could be avoided with multiline string literals if VSCode didn't have an annoying formatting bug\r\n        \"ignorePattern\": \"^}\\\\ from '|^\\\\s+it\\\\(\"\r\n      }\r\n    ],\r\n    \"object-curly-spacing\": [true, \"always\"], // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/objectCurlySpacingRule.md\r\n    // \"sort-imports\": true, // using TSlint's instead // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/sortImportsRule.md\r\n    \"space-in-parens\": [true, \"never\"], // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/spaceInParensRule.md\r\n    \"ter-arrow-body-style\": [true, \"as-needed\"], // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/terArrowBodyStyleRule.md\r\n    // \"ter-arrow-parens\": [true, \"as-needed\"], // using TSlint's instead // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/terArrowParensRule.md\r\n    \"ter-arrow-spacing\": [true], // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/terArrowSpacingRule.md\r\n    \"ter-func-call-spacing\": [true, \"never\"],\r\n    \"ter-prefer-arrow-callback\": true // https://github.com/buzinas/tslint-eslint-rules/blob/master/src/docs/rules/terPreferArrowCallbackRule.md\r\n  }\r\n}\r\n```\r\n\r\n#### Actual behavior\r\n\r\nI'm getting the `Unsafe use of expression of type 'any'` error. I've separated line-by-line and found the culprit to be references to the global JSON object. Even with the type annotation it still throws it. I tried calling it as `(JSON as JSON)` but that doesn't work either.\r\n\r\nWhat's strange is that we have calls using the global JSON object elsewhere, and this behavior only sometimes manifests.\r\nI have a feeling this might be me misunderstanding but I've typed every possible reference in this statement and can't get it to stop.\r\n\r\n#### Expected behavior\r\n\r\nNo  `Unsafe use of expression of type 'any'` error."}}
{"actor":{"display_login":"JoshuaKGoldberg"}}