{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/11777","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/11777/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/11777/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/11777/events","html_url":"https://github.com/Microsoft/TypeScript/issues/11777","id":184426637,"number":11777,"title":"Can't detect the length property of a string type","user":{"login":"arnabdas","id":1061389,"avatar_url":"https://avatars.githubusercontent.com/u/1061389?v=3","gravatar_id":"","url":"https://api.github.com/users/arnabdas","html_url":"https://github.com/arnabdas","followers_url":"https://api.github.com/users/arnabdas/followers","following_url":"https://api.github.com/users/arnabdas/following{/other_user}","gists_url":"https://api.github.com/users/arnabdas/gists{/gist_id}","starred_url":"https://api.github.com/users/arnabdas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arnabdas/subscriptions","organizations_url":"https://api.github.com/users/arnabdas/orgs","repos_url":"https://api.github.com/users/arnabdas/repos","events_url":"https://api.github.com/users/arnabdas/events{/privacy}","received_events_url":"https://api.github.com/users/arnabdas/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Working%20as%20Intended","name":"Working as Intended","color":"fbca04"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-10-21T08:23:06Z","updated_at":"2016-10-21T21:40:15Z","closed_at":"2016-10-21T21:40:15Z","body":"``` bash\r\n$ tsc --version\r\nVersion 2.0.3\r\n```\r\n\r\n**Code**\r\n\r\n```ts\r\npublic static tryParseNumber(str: string = '', radix: number = 10, defaultValue: number = 0): number {\r\n    var retValue = defaultValue;\r\n    if (str !== null) {\r\n      if (typeof str === 'String' && str.length > 0) {\r\n        retValue = parseInt(str, radix);\r\n        if (isNaN(retValue)) {\r\n          retValue = defaultValue;\r\n        }\r\n      }\r\n    }\r\n    return retValue;\r\n  }\r\n\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nThis function should compile correctly\r\n\r\n**Actual behavior:** \r\n\r\nGives error as follows:\r\n\r\n``` bash\r\n(100,42): error TS2339: Property 'length' does not exist on type 'never'.\r\n```\r\n\r\n100th line is `if (typeof str === 'String' && str.length > 0) {`. When I remove the second comparison, with length, it works as expected.\r\n\r\nLive example in TypeScript [play](http://www.typescriptlang.org/play/#src=class%20Greeter%20%7B%0D%0A%20%20%20%20public%20static%20tryParseNumber(str%3A%20string%20%3D%20''%2C%20radix%3A%20number%20%3D%2010%2C%20defaultValue%3A%20number%20%3D%200)%3A%20number%20%7B%0D%0A%20%20%20%20var%20retValue%20%3D%20defaultValue%3B%0D%0A%20%20%20%20if%20(str%20!%3D%3D%20null)%20%7B%0D%0A%20%20%20%20%20%20if%20(typeof%20str%20%3D%3D%3D%20'String'%20%26%26%20str.length%20%3E%200)%20%7B%0D%0A%20%20%20%20%20%20%20%20retValue%20%3D%20parseInt(str%2C%20radix)%3B%0D%0A%20%20%20%20%20%20%20%20if%20(isNaN(retValue))%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20retValue%20%3D%20defaultValue%3B%0D%0A%20%20%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%20%20%7D%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20return%20retValue%3B%0D%0A%20%20%7D%0D%0A%7D%0D%0A%0D%0Alet%20num%20%3D%20Greeter.tryParseNumber('12')%3B%0D%0A%0D%0Alet%20button%20%3D%20document.createElement('button')%3B%0D%0Abutton.textContent%20%3D%20%22Say%20Hello%22%3B%0D%0Abutton.onclick%20%3D%20function()%20%7B%0D%0A%20%20%20%20alert(num)%3B%0D%0A%7D%0D%0A%0D%0Adocument.body.appendChild(button)%3B). See the red squiggly beneath length."},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/255471921","html_url":"https://github.com/Microsoft/TypeScript/issues/11777#issuecomment-255471921","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/11777","id":255471921,"user":{"login":"RyanCavanaugh","id":6685088,"avatar_url":"https://avatars.githubusercontent.com/u/6685088?v=3","gravatar_id":"","url":"https://api.github.com/users/RyanCavanaugh","html_url":"https://github.com/RyanCavanaugh","followers_url":"https://api.github.com/users/RyanCavanaugh/followers","following_url":"https://api.github.com/users/RyanCavanaugh/following{/other_user}","gists_url":"https://api.github.com/users/RyanCavanaugh/gists{/gist_id}","starred_url":"https://api.github.com/users/RyanCavanaugh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RyanCavanaugh/subscriptions","organizations_url":"https://api.github.com/users/RyanCavanaugh/orgs","repos_url":"https://api.github.com/users/RyanCavanaugh/repos","events_url":"https://api.github.com/users/RyanCavanaugh/events{/privacy}","received_events_url":"https://api.github.com/users/RyanCavanaugh/received_events","type":"User","site_admin":false},"created_at":"2016-10-21T21:40:15Z","updated_at":"2016-10-21T21:40:15Z","body":"Please test that your code actually would work before filing a compiler bug?"}}
{"actor":{"display_login":"RyanCavanaugh"}}