Title: Display narrowed type of properties in `completionEntryDetails` · Issue #51526 · microsoft/TypeScript · GitHub
Open Graph Title: Display narrowed type of properties in `completionEntryDetails` · Issue #51526 · microsoft/TypeScript
X Title: Display narrowed type of properties in `completionEntryDetails` · Issue #51526 · microsoft/TypeScript
Description: interface Palette { red?: Color; green?: Color; blue?: Color; } type Color = string | [number, number, number]; function checkOrange(p: Palette) { if (typeof p === "object" && "orange" in p && typeof p.orange === "number") { p./**/ } } R...
Open Graph Description: interface Palette { red?: Color; green?: Color; blue?: Color; } type Color = string | [number, number, number]; function checkOrange(p: Palette) { if (typeof p === "object" && "orange" in p && type...
X Description: interface Palette { red?: Color; green?: Color; blue?: Color; } type Color = string | [number, number, number]; function checkOrange(p: Palette) { if (typeof p === "object" && &qu...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/51526
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Display narrowed type of properties in `completionEntryDetails`","articleBody":"```ts\r\ninterface Palette {\r\n red?: Color;\r\n green?: Color;\r\n blue?: Color;\r\n}\r\n\r\ntype Color = string | [number, number, number];\r\n\r\nfunction checkOrange(p: Palette) {\r\n if (typeof p === \"object\" && \"orange\" in p && typeof p.orange === \"number\") {\r\n p./**/\r\n }\r\n}\r\n```\r\n\r\nRequest completions at `/**/` and select the option for `orange`.\r\n\r\n\u003cdetails>\r\n\u003csummary>\u003cspan>Today, we show\r\n\r\n```\r\n(property) orange: unknown\r\n```\r\n\r\n\u003c/span>\r\n\r\n\r\n\r\n\u003c/summary>\r\n\r\n```json5\r\n[\r\n {\r\n \"name\": \"orange\",\r\n \"kindModifiers\": \"\",\r\n \"kind\": \"property\",\r\n \"displayParts\": [\r\n {\r\n \"text\": \"(\",\r\n \"kind\": \"punctuation\"\r\n },\r\n {\r\n \"text\": \"property\",\r\n \"kind\": \"text\"\r\n },\r\n {\r\n \"text\": \")\",\r\n \"kind\": \"punctuation\"\r\n },\r\n {\r\n \"text\": \" \",\r\n \"kind\": \"space\"\r\n },\r\n {\r\n \"text\": \"orange\",\r\n \"kind\": \"propertyName\"\r\n },\r\n {\r\n \"text\": \":\",\r\n \"kind\": \"punctuation\"\r\n },\r\n {\r\n \"text\": \" \",\r\n \"kind\": \"space\"\r\n },\r\n {\r\n \"text\": \"unknown\",\r\n \"kind\": \"keyword\"\r\n }\r\n ],\r\n \"documentation\": [],\r\n \"tags\": []\r\n }\r\n]\r\n```\r\n\r\n\u003c/details>\r\n\r\nThis has to do with how we decide to display properties - we simply request the type of what `p` is narrowed to, not the type of individual properties. This is actually part of another weirder distinction, where narrowing a property doesn't also narrow the containing value's type.\r\n\r\nRecently there's been some discussion around whether we could do that; however, I am a bit skeptical here. Short of that, it would be nice to show users the actual type they're using.\r\n\r\nThis could get a little bit expensive; but narrowing in general should get cheaper. In theory, #51525 could avoid much of the work, and make the overhead here very low.","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2022-11-14T20:21:30Z","url":"https://github.com/microsoft/TypeScript/issues/51526"}
| 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:e86122b9-bd2e-5685-d809-a7fc61e98868 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A3AE:33251C:6B1A3C:95937E:6B05C2AA |
| html-safe-nonce | 204fd1ad2d6df63c730b7f2502ae9fdcc7e545489f3b6fdf8e7165baefe02241 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBM0FFOjMzMjUxQzo2QjFBM0M6OTU5MzdFOjZCMDVDMkFBIiwidmlzaXRvcl9pZCI6IjUyNTMwMDEwMDYzMjkyMTc3MDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a1908f6bcc8c370e701c1c94f9156ad669f678af3cf547d34a8fd0493e22cbc4 |
| hovercard-subject-tag | issue:1448694963 |
| 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/51526/issue_layout |
| twitter:image | https://opengraph.githubassets.com/92ff0021fab16c38ebfe73583571b16c423c7beb5029584ebdc70728e652c7bd/microsoft/TypeScript/issues/51526 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/92ff0021fab16c38ebfe73583571b16c423c7beb5029584ebdc70728e652c7bd/microsoft/TypeScript/issues/51526 |
| og:image:alt | interface Palette { red?: Color; green?: Color; blue?: Color; } type Color = string | [number, number, number]; function checkOrange(p: Palette) { if (typeof p === "object" && "orange" in p && type... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DanielRosenwasser |
| hostname | github.com |
| expected-hostname | github.com |
| None | 708c2f10d746dbcf1dd80dc8309daa7d595df3fce8066244380fc3238618f09c |
| 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 | 2a29e3cf4fb57e81fd311774f91f345cc4436f40 |
| 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