Title: Generic parameters constrained by polymorphic types allow unsafe operations but are not widened on return positions · Issue #7933 · microsoft/TypeScript · GitHub
Open Graph Title: Generic parameters constrained by polymorphic types allow unsafe operations but are not widened on return positions · Issue #7933 · microsoft/TypeScript
X Title: Generic parameters constrained by polymorphic types allow unsafe operations but are not widened on return positions · Issue #7933 · microsoft/TypeScript
Description: TypeScript Version: 1.9.0-dev.20160405 Code class Animal { name: string; } class Dog extends Animal { bark() {}; } class Cat extends Animal { meow() {}; } class Box
Open Graph Description: TypeScript Version: 1.9.0-dev.20160405 Code class Animal { name: string; } class Dog extends Animal { bark() {}; } class Cat extends Animal { meow() {}; } class Box X Description: TypeScript Version: 1.9.0-dev.20160405 Code class Animal { name: string; } class Dog extends Animal { bark() {}; } class Cat extends Animal { meow() {}; } class Box<V> { item: V; } function f...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/7933
X: @github
Domain: github.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generic parameters constrained by polymorphic types allow unsafe operations but are not widened on return positions","articleBody":"**TypeScript Version:**\n\n1.9.0-dev.20160405\n\n**Code**\n\n``` ts\nclass Animal {\n name: string;\n}\n\nclass Dog extends Animal {\n bark() {};\n}\n\nclass Cat extends Animal {\n meow() {};\n}\n\nclass Box\u003cV> {\n item: V;\n}\n\nfunction f\u003cT extends Box\u003cAnimal>>(box: T) {\n box.item = new Cat(); // \u003c-- This is perfectly valid and allowed by the constraint\n return box; // \u003c-- The returned type is T\n}\n\nlet result = f(new Box\u003cDog>()); // Type of 'result' is inferred as Box\u003cDog>\nresult.item.bark(); // \u003c-- No compilation error. Run-time error..\n```\n\n**Expected behavior:**\nType of `result` should be inferred as `Box\u003cAnimal>`.\n`result.item.bark();` should give a compilation error.\n\n**Actual behavior:** \nType of `result` is inferred as `Box\u003cDog>`.\n`result.item.bark();` does not error at compile-time but does error at run-time.\n\n**Comments:**\nType of `box` should be widened from `T` to `Box\u003cAnimal>` within the body of the function, as there is no (current) way to ensure the members of `box` are not reassigned with types incompatible to the ones specified in `T`. The return type should therefore be `Box\u003cAnimal>` and not `T`.\n\n_[Edits: rewritten main example, heavily shortened and removed unneeded sections]_\n","author":{"url":"https://github.com/malibuzios","@type":"Person","name":"malibuzios"},"datePublished":"2016-04-07T13:41:23Z","url":"https://github.com/microsoft/TypeScript/issues/7933"}
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:095f0db4-7615-585c-022d-7f67f2e0e36c current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id AAA2:38C5CF:268DC25:30EA9AE:6B0176A4 html-safe-nonce 8505080e5850e8aea8030dddc32402e1aab8e046e0ade8e7c8f3dd9661211eca visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQUEyOjM4QzVDRjoyNjhEQzI1OjMwRUE5QUU6NkIwMTc2QTQiLCJ2aXNpdG9yX2lkIjoiNzY3MzEyNjE1MDMyNzA3MjQyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 visitor-hmac 3843002b8884a61de8358eb0bbc16ba84070e73cf0fd4f5eaf33f19d7913b833 hovercard-subject-tag issue:146629240 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/7933/issue_layout twitter:image https://opengraph.githubassets.com/20f0e6f6364d3e1f79e035d60ad665561bc3cddd861f7124863193f648c65e47/microsoft/TypeScript/issues/7933 twitter:card summary_large_image og:image https://opengraph.githubassets.com/20f0e6f6364d3e1f79e035d60ad665561bc3cddd861f7124863193f648c65e47/microsoft/TypeScript/issues/7933 og:image:alt TypeScript Version: 1.9.0-dev.20160405 Code class Animal { name: string; } class Dog extends Animal { bark() {}; } class Cat extends Animal { meow() {}; } class Box og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username malibuzios 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
URLs of crawlers that visited me.