Title: Function signature confusion after ternary operator · Issue #35707 · microsoft/TypeScript · GitHub
Open Graph Title: Function signature confusion after ternary operator · Issue #35707 · microsoft/TypeScript
X Title: Function signature confusion after ternary operator · Issue #35707 · microsoft/TypeScript
Description: I'm expecting this to not be a bug but I can't seem to figure out what else it could be. Basically I'm trying to create a (TLS)Socket instance using the core Node.js net or tls modules depending on a condition. Instantiating them by dire...
Open Graph Description: I'm expecting this to not be a bug but I can't seem to figure out what else it could be. Basically I'm trying to create a (TLS)Socket instance using the core Node.js net or tls modules depending on...
X Description: I'm expecting this to not be a bug but I can't seem to figure out what else it could be. Basically I'm trying to create a (TLS)Socket instance using the core Node.js net or tls modules ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/35707
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Function signature confusion after ternary operator","articleBody":"I'm expecting this to not be a bug but I can't seem to figure out what else it could be.\r\nBasically I'm trying to create a `(TLS)Socket` instance using the core Node.js `net` or `tls` modules depending on a condition.\r\nInstantiating them by directly referencing the module works fine but whenever I introduce a level of indirection by conditionally defining the TCP client module, compilation breaks.\r\n\r\n**Code**\r\n\r\n```ts\r\nimport net from 'net';\r\nimport tls from 'tls';\r\n\r\nconst socketA = net.connect({ host: 'localhost', port: 1234 });\r\nconst socketB = tls.connect({ host: 'localhost', port: 1234 });\r\n\r\nconst protocol = process.argv[2];\r\nconst client = protocol === 'https' ? tls : net;\r\nconst socketC: net.Socket | tls.TLSSocket = client.connect({ host: 'localhost', port: 1234 });\r\n\r\nconsole.log(socketA, socketB, socketC);\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nSuccessful compilation.\r\n\r\n**Actual behavior:**\r\n\r\n```\r\nThis expression is not callable.\r\n Each member of the union type\r\n '{ (options: NetConnectOpts, connectionListener?: (() => void) | undefined): Socket;\r\n (port: number, host?: string | undefined, connectionListener?: (() => void) | undefined): Socket; \r\n (path: string, connectionListener?: (() => void) | undefined): Socket; } | { ...; }'\r\nhas signatures, but none of those signatures are compatible with each other.\r\n\r\n12 const socketC = client.connect({ host: 'localhost', port: 443 });\r\n ~~~~~~~\r\n```\r\n\r\n**Playground Link:**\r\n\r\n[Playground Link](https://www.typescriptlang.org/play/?module=1#code/OQVwzgpgBGAuBOBLAxrYBuAUJxBbADgPbyxQB2EpAZvIblMBWlnkSVLADZhQ10NcwGbMkJk4MQsgDWlAIJQAvOUoA6UWQqoAFAG8oAC0JwAXA05SAhpyNxgAGihtYZgIwAmAMwAWKAF8ASiwNCTApWVgAISUObnUxLVg9Q2MXcysbVIcnYjSPH38gkTEJfFpYKUJOGLKpCDAwVUt4AHMANwBtdwBdYJLSZE5ECDJSZVqK0WrFGYYDWFh8ISgAflieMyY+8VIwmUoAYU21AGVwyigAHwACwVUAFQAZE7P9sahB4dH4zQgdfVsaWAFmQ1kB2Wcbi8vkCWEwISqEFUFha2j2ETkjnRlEiWPOsAOQSAA)\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\n","author":{"url":"https://github.com/Mickael-van-der-Beek","@type":"Person","name":"Mickael-van-der-Beek"},"datePublished":"2019-12-16T20:41:07Z","url":"https://github.com/microsoft/TypeScript/issues/35707"}
| 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:1cf38fa1-a1aa-cdcb-4ee7-873b913c4af4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 928A:CC1A4:603650:7C6C6F:6B00DDCB |
| html-safe-nonce | 403d9f8ab7bfc2736973ade42b5f17a2fb89eec05b656ac0dcaf6f3f732daff5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MjhBOkNDMUE0OjYwMzY1MDo3QzZDNkY6NkIwMEREQ0IiLCJ2aXNpdG9yX2lkIjoiMzIzMjM1MjQxOTc5OTE2MjMxNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | eaec2b825d63ff5be7cec333fad93a4d997a133ffcb7d81079e8448bd95661dd |
| hovercard-subject-tag | issue:538643521 |
| 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/35707/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dc7205f21bfb63d285cde8be0389d6f96c01eef2f0ace851b8274ef6b9d76d10/microsoft/TypeScript/issues/35707 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dc7205f21bfb63d285cde8be0389d6f96c01eef2f0ace851b8274ef6b9d76d10/microsoft/TypeScript/issues/35707 |
| og:image:alt | I'm expecting this to not be a bug but I can't seem to figure out what else it could be. Basically I'm trying to create a (TLS)Socket instance using the core Node.js net or tls modules depending on... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Mickael-van-der-Beek |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| 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 | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width