Title: is this a Generic bug? · Issue #3275 · microsoft/TypeScript · GitHub
Open Graph Title: is this a Generic bug? · Issue #3275 · microsoft/TypeScript
X Title: is this a Generic bug? · Issue #3275 · microsoft/TypeScript
Description: consider the following class. class GenericPractice
Open Graph Description: consider the following class. class GenericPractice
X Description: consider the following class. class GenericPractice<T>{ private entity: T; constructor(entity: T) { this.entity = entity; } public add(item: T): string { return item.toString(); } } class Cou...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/3275
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"is this a Generic bug?","articleBody":"consider the following class.\n\n```\nclass GenericPractice\u003cT>{\n private entity: T;\n constructor(entity: T) {\n this.entity = entity;\n }\n\n public add(item: T): string {\n return item.toString();\n }\n\n}\nclass CouponInfo {\n public toString(): string {\n return \"couponInfo\";\n }\n}\nclass Snake{\n}\n\n var genericPractice = new GenericPractice\u003cCouponInfo>(new CouponInfo());\ngenericPractice.add(new Snake(\"Sammy the Python\")));\n\n```\n\ntheoretically, the above last line:\n\n```\ngenericPractice.add(new Snake(\"Sammy the Python\")));\n```\n\nshould have compile time error since the generic of class GenericPractice should only allow CouponInfo in method add, not Snake.\n\nHowever, the compile still passes which violates the fundamental concept of generic.\nis this a bug?\n","author":{"url":"https://github.com/Paul-Lo","@type":"Person","name":"Paul-Lo"},"datePublished":"2015-05-27T05:27:11Z","url":"https://github.com/microsoft/TypeScript/issues/3275"}
| 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:7037dd5d-8415-9d97-0791-7c6518511dbf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AA36:62F48:22BEC8:2DE8BD:6B01BD09 |
| html-safe-nonce | 3ecead542857b129ec9c8993025dd6b8255eaefe799a8bf9e162b87133f3d45f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQTM2OjYyRjQ4OjIyQkVDODoyREU4QkQ6NkIwMUJEMDkiLCJ2aXNpdG9yX2lkIjoiODcyMDQxNDY2MDg2NTY3MDQwOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | bb78dffb34682dba9b631125607c3bd9964da1bb36ae0f191b2122dd43dc6e70 |
| hovercard-subject-tag | issue:81285468 |
| 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/3275/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d48b77414820525e1de4adc0915f29a398ca033e92734fff84f3a5b9f5461fb5/microsoft/TypeScript/issues/3275 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d48b77414820525e1de4adc0915f29a398ca033e92734fff84f3a5b9f5461fb5/microsoft/TypeScript/issues/3275 |
| og:image:alt | consider the following class. class GenericPractice |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Paul-Lo |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width