Title: Compiles without error when the return type signature of variable doesn't match that of the generic function that it is being assigned to · Issue #5616 · microsoft/TypeScript · GitHub
Open Graph Title: Compiles without error when the return type signature of variable doesn't match that of the generic function that it is being assigned to · Issue #5616 · microsoft/TypeScript
X Title: Compiles without error when the return type signature of variable doesn't match that of the generic function that it is being assigned to · Issue #5616 · microsoft/TypeScript
Description: Compiling the code below: function identity
Open Graph Description: Compiling the code below: function identity
X Description: Compiling the code below: function identity<T>(arg: T): T { return arg; } var myIdentity: <T>(arg: T) => string = identity; var a = myIdentity<string>("string") var b...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/5616
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Compiles without error when the return type signature of variable doesn't match that of the generic function that it is being assigned to","articleBody":"Compiling the code below:\n\n```\nfunction identity\u003cT>(arg: T): T {\n return arg;\n}\n\nvar myIdentity: \u003cT>(arg: T) => string = identity;\n\nvar a = myIdentity\u003cstring>(\"string\")\nvar b = myIdentity\u003cnumber>(100)\n```\n\noutputs the following javascript:\n\n```\nfunction identity(arg) {\n return arg;\n}\nvar myIdentity = identity;\nvar a = myIdentity(\"string\");\nvar b = myIdentity(100);\n```\n\nI put the type signature of the variable `myIdentity` as `\u003cT>(arg: T) => string`\nwhere the return type is `string` instead of `T` (that I expect to be correct).\n\nI expected the Typescript compiler to show an error because the return types\ndon't match. However, the code compiled without any error.\n\nSpecs:\n\nMac OS X 10.11\n\n`tsc --version` outputs:\n`message TS6029: Version 1.6.2`\n","author":{"url":"https://github.com/prateekbhatt","@type":"Person","name":"prateekbhatt"},"datePublished":"2015-11-11T19:47:07Z","url":"https://github.com/microsoft/TypeScript/issues/5616"}
| 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:886cb361-0d86-9ae5-8c29-df7165fbaaff |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BA80:31B4CC:481E3B:60D39D:6B00CA1C |
| html-safe-nonce | be96ae25437c6718562282410cb1143f0e87ecb9abff87f004c5a37c4001a086 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTgwOjMxQjRDQzo0ODFFM0I6NjBEMzlEOjZCMDBDQTFDIiwidmlzaXRvcl9pZCI6IjE5NzM4NDk0NDM1NTE3MjYxMDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3b484de5e0c549b928bc634a007848194311f54ddbe7147140785b56427c6361 |
| hovercard-subject-tag | issue:116407789 |
| 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/5616/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3a5b17837f2d4e0fc1a4924ea4cf3b8e7315ddb8b0859e9165111df9fcd3d1a8/microsoft/TypeScript/issues/5616 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3a5b17837f2d4e0fc1a4924ea4cf3b8e7315ddb8b0859e9165111df9fcd3d1a8/microsoft/TypeScript/issues/5616 |
| og:image:alt | Compiling the code below: function identity |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | prateekbhatt |
| hostname | github.com |
| expected-hostname | github.com |
| None | 98dc00e171c204462a6f367482a0f8c3c6b5dbca99cd7390e82d2df49ce096e4 |
| 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 | ef013399cf0a3c324bea644a685d7c1e0f06b5b7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width