Title: The type of private fields in a class cannot be used in generic · Issue #30882 · microsoft/TypeScript · GitHub
Open Graph Title: The type of private fields in a class cannot be used in generic · Issue #30882 · microsoft/TypeScript
X Title: The type of private fields in a class cannot be used in generic · Issue #30882 · microsoft/TypeScript
Description: TypeScript Version: 3.4.1 Search Terms: generic, class, private field Code class Foo
Open Graph Description: TypeScript Version: 3.4.1 Search Terms: generic, class, private field Code class Foo
X Description: TypeScript Version: 3.4.1 Search Terms: generic, class, private field Code class Foo<T> { private a!: T; // when it is public, no error occurs below } type Bar<T extends Record<string, ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/30882
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"The type of private fields in a class cannot be used in generic","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.4.1\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:**\r\ngeneric, class, private field\r\n**Code**\r\n```ts\r\nclass Foo\u003cT> {\r\n private a!: T; // when it is public, no error occurs below\r\n}\r\n\r\ntype Bar\u003cT extends Record\u003cstring, Foo\u003cany>>> = T[keyof T][\"a\"]; // ts(2536) occurs, while autocomplete works well.\r\ntype A = Foo\u003cnumber>[\"a\"]; // it works always!\r\n```\r\n\r\n**Expected behavior:**\r\nNot treating it as an error. If it is inteneded, at least the error message should be more helpful.\r\n**Actual behavior:**\r\nts(2536) occurs.\r\n[**Playground Link**](https://www.typescriptlang.org/play/#src=class%20Foo%3CT%3E%20%7B%0D%0A%20%20%20%20private%20a!%3A%20T%3B%20%2F%2F%20when%20it%20is%20public%2C%20no%20error%20occurs%20below%0D%0A%7D%0D%0A%0D%0Atype%20Bar%3CT%20extends%20Record%3Cstring%2C%20Foo%3Cany%3E%3E%3E%20%3D%20T%5Bkeyof%20T%5D%5B%22a%22%5D%3B%20%2F%2F%20ts(2536)%20occurs%2C%20while%20autocomplete%20works%20well.%0D%0Atype%20A%20%3D%20Foo%3Cnumber%3E%5B%22a%22%5D%3B%20%2F%2F%20it%20works%20always!) \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior -->\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->","author":{"url":"https://github.com/worudso","@type":"Person","name":"worudso"},"datePublished":"2019-04-12T08:31:24Z","url":"https://github.com/microsoft/TypeScript/issues/30882"}
| 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:1a665d7e-6af4-c695-8665-5389137125ac |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 834A:23CF06:FB7090:14372C2:6B01006F |
| html-safe-nonce | 1e9e079caf2b75ddccf240f0d09cc99214aae54dcbd9adbb6b4834c484d06b83 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MzRBOjIzQ0YwNjpGQjcwOTA6MTQzNzJDMjo2QjAxMDA2RiIsInZpc2l0b3JfaWQiOiIzNjc4MDU3MDk3NTQ4ODU3NDU1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ad9353283b8259ae872f838ec1d04f11e095b1370d3c62e701294eb00511270d |
| hovercard-subject-tag | issue:432448921 |
| 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/30882/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4ce395ea7b5f35bf7bdc113072b2fda7c7e9998852c4e6cff3d13e8c72b1abdd/microsoft/TypeScript/issues/30882 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4ce395ea7b5f35bf7bdc113072b2fda7c7e9998852c4e6cff3d13e8c72b1abdd/microsoft/TypeScript/issues/30882 |
| og:image:alt | TypeScript Version: 3.4.1 Search Terms: generic, class, private field Code class Foo |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | worudso |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width