Title: Generic parameter is considered object · Issue #27093 · microsoft/TypeScript · GitHub
Open Graph Title: Generic parameter is considered object · Issue #27093 · microsoft/TypeScript
X Title: Generic parameter is considered object · Issue #27093 · microsoft/TypeScript
Description: TypeScript Version: 3.1.0-dev.201xxxxx Search Terms: generics, typeof, object, never Code function f
Open Graph Description: TypeScript Version: 3.1.0-dev.201xxxxx Search Terms: generics, typeof, object, never Code function f
X Description: TypeScript Version: 3.1.0-dev.201xxxxx Search Terms: generics, typeof, object, never Code function f<TData>(data: TData): boolean { if (typeof data === "object") return true; return...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/27093
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generic parameter is considered object","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 3.1.0-dev.201xxxxx\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** generics, typeof, object, never\r\n\r\n**Code**\r\n\r\n```ts\r\nfunction f\u003cTData>(data: TData): boolean {\r\n if (typeof data === \"object\") return true;\r\n return data;\r\n}\r\n\r\nlet x: boolean = f(1);\r\n```\r\n\r\n**Expected behavior:**\r\nCode should not compile - function actually returns boolean | TData, but states only boolean\r\n\r\n**Actual behavior:**\r\nCode compiles without errors. After the if statement, data is considered **never**\r\n\r\n**Playground Link:** \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior --> http://www.typescriptlang.org/play/#src=function%20f%3CTData%3E(data%3A%20TData)%3A%20boolean%20%7B%0D%0A%20%20%20%20if%20(typeof%20data%20%3D%3D%3D%20%27object%27)%0D%0A%20%20%20%20%20%20%20%20return%20true%3B%0D%0A%20%20%20%20return%20data%3B%0D%0A%7D%0D%0A%0D%0Alet%20x%3A%20boolean%20%3D%20f(1)%3B\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\n","author":{"url":"https://github.com/svatal","@type":"Person","name":"svatal"},"datePublished":"2018-09-14T14:44:41Z","url":"https://github.com/microsoft/TypeScript/issues/27093"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:51ce6eca-4195-74fb-41f5-940e7ebca327 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8F82:33F105:6E433:980A2:6B04AAF1 |
| html-safe-nonce | e994148fc911c397f8618561985ff85b7389285ad1f6261b1dc9a11bed06b8c8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RjgyOjMzRjEwNTo2RTQzMzo5ODBBMjo2QjA0QUFGMSIsInZpc2l0b3JfaWQiOiI0MzQ3NDg3NDkzNjI1Nzg1MDczIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d9fd1be4b5637baa608fae156bf6793034792dd132d2de0cb266dac03f971535 |
| hovercard-subject-tag | issue:360334617 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/27093/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d482698531871ad30ac2f32de26e3ce4fbc85f5da1223989ad498d42dc5cca48/microsoft/TypeScript/issues/27093 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d482698531871ad30ac2f32de26e3ce4fbc85f5da1223989ad498d42dc5cca48/microsoft/TypeScript/issues/27093 |
| og:image:alt | TypeScript Version: 3.1.0-dev.201xxxxx Search Terms: generics, typeof, object, never Code function f |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | svatal |
| hostname | github.com |
| expected-hostname | github.com |
| None | f1d110ea058a0915c1d8aa3fc2069fa15801e128f591e5762525abe77490ecb1 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ffa22a65e4c46d376940fe34b05e6a7e9c7fdb9b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width