Title: Inherited types in callback functions · Issue #222 · microsoft/TypeScript · GitHub
Open Graph Title: Inherited types in callback functions · Issue #222 · microsoft/TypeScript
X Title: Inherited types in callback functions · Issue #222 · microsoft/TypeScript
Description: Typescript is too lenient when accepting sub-classes in inherited types. For example: interface Base { baseField: string; } interface Child extends Base { childField: number; } var test = function (callbackfn: (value: Base) => void): voi...
Open Graph Description: Typescript is too lenient when accepting sub-classes in inherited types. For example: interface Base { baseField: string; } interface Child extends Base { childField: number; } var test = function ...
X Description: Typescript is too lenient when accepting sub-classes in inherited types. For example: interface Base { baseField: string; } interface Child extends Base { childField: number; } var test = function ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/222
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inherited types in callback functions","articleBody":"Typescript is too lenient when accepting sub-classes in inherited types. For example:\n\n``` TypeScript\ninterface Base {\n baseField: string;\n}\ninterface Child extends Base {\n childField: number;\n}\n\nvar test = function (callbackfn: (value: Base) => void): void {\n callbackfn({baseField: \"\"});\n};\n\nvar callTest = function() {\n test(function (value: Child) {\n console.log(value.childField);\n });\n};\n```\n\nshould not compile, as `callbackfn` requires a Base, not a Child. It is not correct that value is a child. If Child does not extend Base, then this causes a compile error as expected. However, if we add no explicit hierarchy between the classes, but change the example to \n\n``` TypeScript\ninterface Base {\n baseField: string;\n}\ninterface Child {\n baseField: string; \n childField: number;\n}\n\nvar test = function (callbackfn: (value: Base) => void): void {\n callbackfn({baseField: \"\"});\n};\n\nvar callTest = function() {\n test(function (value: Child) {\n console.log(value.childField);\n });\n};\n```\n\nthen the code still compiles. Both of these are errors that should hopefully be caught at compile time. It looks like typescript only checks to see if a callback parameter is valid if the classes have common members. This should be changed to a subset.\n","author":{"url":"https://github.com/arknave","@type":"Person","name":"arknave"},"datePublished":"2014-07-24T00:11:14Z","url":"https://github.com/microsoft/TypeScript/issues/222"}
| 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:d03f3a10-bd54-a7a9-3eaf-25f5e35c8d57 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D732:2BA6E:343469:464D91:6B0089B2 |
| html-safe-nonce | 83bb5f330e29518c8a64ce7b3ed5c2ec11fd4f53facad6de2d5e0979d45e2c71 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzMyOjJCQTZFOjM0MzQ2OTo0NjREOTE6NkIwMDg5QjIiLCJ2aXNpdG9yX2lkIjoiNzExOTg3MDA4NDEyMTY1OTgyNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2e73e725d8ab28d52ba0a3095d07747a2d6fb0e118df04da47e9a150a6ff9457 |
| hovercard-subject-tag | issue:38586239 |
| 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/222/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f365996538dfb5c8d8e950bcccbc0e5735ffb6526e98a53ba7fe89511a5d77b7/microsoft/TypeScript/issues/222 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f365996538dfb5c8d8e950bcccbc0e5735ffb6526e98a53ba7fe89511a5d77b7/microsoft/TypeScript/issues/222 |
| og:image:alt | Typescript is too lenient when accepting sub-classes in inherited types. For example: interface Base { baseField: string; } interface Child extends Base { childField: number; } var test = function ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | arknave |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4d3d8e50f02c1d7bf86d5acfa1d3bfe9366abd6528a6b429eb07a168429d2b61 |
| 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 | db758f8e02b8257935fb03edf81a3e76eb3abd11 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width