René's URL Explorer Experiment


Title: Type simultaneously does and does not have property · Issue #30657 · microsoft/TypeScript · GitHub

Open Graph Title: Type simultaneously does and does not have property · Issue #30657 · microsoft/TypeScript

X Title: Type simultaneously does and does not have property · Issue #30657 · microsoft/TypeScript

Description: TypeScript Version: 3.4.1 and 3.2.2 Code interface TextChannel { id: string; type: 'text'; phoneNumber: string; } interface EmailChannel { id: string; type: 'email'; addres: string; } type Channel = TextChannel | EmailChannel; export typ...

Open Graph Description: TypeScript Version: 3.4.1 and 3.2.2 Code interface TextChannel { id: string; type: 'text'; phoneNumber: string; } interface EmailChannel { id: string; type: 'email'; addres: string; } type Channel ...

X Description: TypeScript Version: 3.4.1 and 3.2.2 Code interface TextChannel { id: string; type: 'text'; phoneNumber: string; } interface EmailChannel { id: string; type: 'email'; addres: string;...

Opengraph URL: https://github.com/microsoft/TypeScript/issues/30657

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type simultaneously does and does not have property","articleBody":"**TypeScript Version:**  3.4.1 and 3.2.2\r\n\r\n**Code**\r\n\r\n```ts\r\ninterface TextChannel {\r\n    id: string;\r\n    type: 'text';\r\n    phoneNumber: string;\r\n}\r\n\r\ninterface EmailChannel {\r\n    id: string;\r\n    type: 'email';\r\n    addres: string;\r\n}\r\n\r\ntype Channel = TextChannel | EmailChannel;\r\n\r\nexport type ChannelType = Channel extends { type: infer R } ? R : never; // 'text' | 'email'\r\n\r\n// Stolen from lodash.\r\ntype Omit\u003cT, K extends keyof T> = Pick\u003c\r\n    T,\r\n    ({ [P in keyof T]: P } & { [P in K]: never } & { [x: string]: never })[keyof T]\r\n>;\r\n\r\ntype ChannelOfType\u003cT extends ChannelType, A = Channel> = A extends { type: T }\r\n    ? A\r\n    : never;\r\n\r\n/**\r\n * A NewChannel is a Channel with a 'type', a 'localChannelId', with no id,\r\n * and every other field is optional.\r\n */\r\nexport type NewChannel\u003cT extends Channel> = Pick\u003cT, 'type'> &\r\n    Partial\u003cOmit\u003cT, 'type' | 'id'>> & { localChannelId: string };\r\n\r\n/**\r\n * Create a NewChannel of the specified type, ready to hand off to, for example,\r\n * a react form which can fill it in with values and turn it into a real Channel.\r\n */\r\nexport function makeNewChannel\u003cT extends ChannelType>(type: T): NewChannel\u003cChannelOfType\u003cT>> {\r\n    const localChannelId = `blahblahblah`;\r\n    return { type, localChannelId };\r\n}\r\n\r\n// Here's the exciting bit:\r\n\r\nconst newTextChannel = makeNewChannel('text');\r\n// Property 'phoneNumber' does not exist on type 'NewChannel\u003cTextChannel>'. ts(2339)\r\nnewTextChannel.phoneNumber = '613-555-1234';\r\n\r\nconst newTextChannel2 : NewChannel\u003cTextChannel> = makeNewChannel('text');\r\n// But this works!\r\nnewTextChannel2.phoneNumber = '613-555-1234';\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nSince `newTextChannel` and `newTextChannel2` are both of type `NewChannel\u003cTextChannel>`, I'd expect them both to have a `phoneNumber` property (or both to not have a `phoneNumber` property).\r\n\r\n**Actual behavior:**\r\n\r\n`newTextChannel` does not have this property, and `newTextChannel2` does, even though these two seem to be of the same type!\r\n\r\n**Playground Link:** [link](https://www.typescriptlang.org/play/#src=interface%20TextChannel%20%7B%0D%0A%20%20%20%20id%3A%20string%3B%0D%0A%20%20%20%20type%3A%20'text'%3B%0D%0A%20%20%20%20phoneNumber%3A%20string%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20EmailChannel%20%7B%0D%0A%20%20%20%20id%3A%20string%3B%0D%0A%20%20%20%20type%3A%20'email'%3B%0D%0A%20%20%20%20addres%3A%20string%3B%0D%0A%7D%0D%0A%0D%0Atype%20Channel%20%3D%20TextChannel%20%7C%20EmailChannel%3B%0D%0A%0D%0Aexport%20type%20ChannelType%20%3D%20Channel%20extends%20%7B%20type%3A%20infer%20R%20%7D%20%3F%20R%20%3A%20never%3B%20%2F%2F%20'text'%20%7C%20'email'%0D%0A%0D%0A%2F%2F%20Stolen%20from%20lodash.%0D%0Atype%20Omit%3CT%2C%20K%20extends%20keyof%20T%3E%20%3D%20Pick%3C%0D%0A%20%20%20%20T%2C%0D%0A%20%20%20%20(%7B%20%5BP%20in%20keyof%20T%5D%3A%20P%20%7D%20%26%20%7B%20%5BP%20in%20K%5D%3A%20never%20%7D%20%26%20%7B%20%5Bx%3A%20string%5D%3A%20never%20%7D)%5Bkeyof%20T%5D%0D%0A%3E%3B%0D%0A%0D%0Atype%20ChannelOfType%3CT%20extends%20ChannelType%2C%20A%20%3D%20Channel%3E%20%3D%20A%20extends%20%7B%20type%3A%20T%20%7D%0D%0A%20%20%20%20%3F%20A%0D%0A%20%20%20%20%3A%20never%3B%0D%0A%0D%0A%2F**%0D%0A%20*%20A%20NewChannel%20is%20a%20Channel%20with%20a%20'type'%2C%20a%20'localChannelId'%2C%20with%20no%20id%2C%0D%0A%20*%20and%20every%20other%20field%20is%20optional.%0D%0A%20*%2F%0D%0Aexport%20type%20NewChannel%3CT%20extends%20Channel%3E%20%3D%20Pick%3CT%2C%20'type'%3E%20%26%0D%0A%20%20%20%20Partial%3COmit%3CT%2C%20'type'%20%7C%20'id'%3E%3E%20%26%20%7B%20localChannelId%3A%20string%20%7D%3B%0D%0A%0D%0A%2F**%0D%0A%20*%20Create%20a%20NewChannel%20of%20the%20specified%20type%2C%20ready%20to%20hand%20off%20to%2C%20for%20example%2C%0D%0A%20*%20a%20react%20form%20which%20can%20fill%20it%20in%20with%20values%20and%20turn%20it%20into%20a%20real%20Channel.%0D%0A%20*%2F%0D%0Aexport%20function%20makeNewChannel%3CT%20extends%20ChannelType%3E(type%3A%20T)%3A%20NewChannel%3CChannelOfType%3CT%3E%3E%20%7B%0D%0A%20%20%20%20const%20localChannelId%20%3D%20%60blahblahblah%60%3B%0D%0A%20%20%20%20return%20%7B%20type%2C%20localChannelId%20%7D%3B%0D%0A%7D%0D%0A%0D%0A%2F%2F%20Here's%20the%20exciting%20bit%3A%0D%0A%0D%0Aconst%20newTextChannel%20%3D%20makeNewChannel('text')%3B%0D%0A%2F%2F%20Property%20'phoneNumber'%20does%20not%20exist%20on%20type%20'NewChannel%3CTextChannel%3E'.ts(2339)%0D%0AnewTextChannel.phoneNumber%20%3D%20'613-555-1234'%3B%0D%0A%0D%0Aconst%20newTextChannel2%20%3A%20NewChannel%3CTextChannel%3E%20%3D%20makeNewChannel('text')%3B%0D%0A%2F%2F%20But%20this%20works!%0D%0AnewTextChannel2.phoneNumber%20%3D%20'613-555-1234'%3B%0D%0A)\r\n\r\n**Related Issues:** No\r\n","author":{"url":"https://github.com/jwalton","@type":"Person","name":"jwalton"},"datePublished":"2019-03-30T03:09:21Z","url":"https://github.com/microsoft/TypeScript/issues/30657"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:8b6e1d6e-fc18-9e66-5331-a54b7f40b92b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCE9A:3D4705:B2CDFF:E76ED5:6B00E79E
html-safe-nonceee3586f90046bb63d8b640d6e243ac7b2568bbcede4a45bb3f19920fdf0ca70d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRTlBOjNENDcwNTpCMkNERkY6RTc2RUQ1OjZCMDBFNzlFIiwidmlzaXRvcl9pZCI6IjQ0MzQwODA3NTU5MzY3MTY3MDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac16ae0901897db797f38a7cea24746137d5caace2e8789060eecd81adef533368
hovercard-subject-tagissue:427235031
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/30657/issue_layout
twitter:imagehttps://opengraph.githubassets.com/7c219e3a4197a5e079a6f21abf5e61ccaa4c4aaef8999efb6df60c7c89e73286/microsoft/TypeScript/issues/30657
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/7c219e3a4197a5e079a6f21abf5e61ccaa4c4aaef8999efb6df60c7c89e73286/microsoft/TypeScript/issues/30657
og:image:altTypeScript Version: 3.4.1 and 3.2.2 Code interface TextChannel { id: string; type: 'text'; phoneNumber: string; } interface EmailChannel { id: string; type: 'email'; addres: string; } type Channel ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejwalton
hostnamegithub.com
expected-hostnamegithub.com
None27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14
turbo-cache-controlno-preview
go-importgithub.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id20929025
octolytics-dimension-repository_nwomicrosoft/TypeScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id20929025
octolytics-dimension-repository_network_root_nwomicrosoft/TypeScript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release624179fb8b88d26ba5bba08894eb60a1c5a1d93d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/30657#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F30657
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F30657
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=microsoft%2FTypeScript
Reloadhttps://github.com/microsoft/TypeScript/issues/30657
Reloadhttps://github.com/microsoft/TypeScript/issues/30657
Reloadhttps://github.com/microsoft/TypeScript/issues/30657
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests308 (308)https://github.com/microsoft/TypeScript/pulls
Actionshttps://github.com/microsoft/TypeScript/actions
Projectshttps://github.com/microsoft/TypeScript/projects
Wikihttps://github.com/microsoft/TypeScript/wiki
Security and qualityhttps://github.com/microsoft/TypeScript/security
Insightshttps://github.com/microsoft/TypeScript/insights
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/30657
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/30657
#30753https://github.com/microsoft/TypeScript/pull/30753
Type simultaneously does and does not have propertyhttps://github.com/microsoft/TypeScript/issues/30657#top
#30753https://github.com/microsoft/TypeScript/pull/30753
https://github.com/weswigham
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
https://github.com/jwalton
Jason Walton (jwalton)https://github.com/jwalton
on Mar 30, 2019https://github.com/microsoft/TypeScript/issues/30657#issue-427235031
linkhttps://www.typescriptlang.org/play/#src=interface%20TextChannel%20%7B%0D%0A%20%20%20%20id%3A%20string%3B%0D%0A%20%20%20%20type%3A%20'text'%3B%0D%0A%20%20%20%20phoneNumber%3A%20string%3B%0D%0A%7D%0D%0A%0D%0Ainterface%20EmailChannel%20%7B%0D%0A%20%20%20%20id%3A%20string%3B%0D%0A%20%20%20%20type%3A%20'email'%3B%0D%0A%20%20%20%20addres%3A%20string%3B%0D%0A%7D%0D%0A%0D%0Atype%20Channel%20%3D%20TextChannel%20%7C%20EmailChannel%3B%0D%0A%0D%0Aexport%20type%20ChannelType%20%3D%20Channel%20extends%20%7B%20type%3A%20infer%20R%20%7D%20%3F%20R%20%3A%20never%3B%20%2F%2F%20'text'%20%7C%20'email'%0D%0A%0D%0A%2F%2F%20Stolen%20from%20lodash.%0D%0Atype%20Omit%3CT%2C%20K%20extends%20keyof%20T%3E%20%3D%20Pick%3C%0D%0A%20%20%20%20T%2C%0D%0A%20%20%20%20(%7B%20%5BP%20in%20keyof%20T%5D%3A%20P%20%7D%20%26%20%7B%20%5BP%20in%20K%5D%3A%20never%20%7D%20%26%20%7B%20%5Bx%3A%20string%5D%3A%20never%20%7D)%5Bkeyof%20T%5D%0D%0A%3E%3B%0D%0A%0D%0Atype%20ChannelOfType%3CT%20extends%20ChannelType%2C%20A%20%3D%20Channel%3E%20%3D%20A%20extends%20%7B%20type%3A%20T%20%7D%0D%0A%20%20%20%20%3F%20A%0D%0A%20%20%20%20%3A%20never%3B%0D%0A%0D%0A%2F**%0D%0A%20*%20A%20NewChannel%20is%20a%20Channel%20with%20a%20'type'%2C%20a%20'localChannelId'%2C%20with%20no%20id%2C%0D%0A%20*%20and%20every%20other%20field%20is%20optional.%0D%0A%20*%2F%0D%0Aexport%20type%20NewChannel%3CT%20extends%20Channel%3E%20%3D%20Pick%3CT%2C%20'type'%3E%20%26%0D%0A%20%20%20%20Partial%3COmit%3CT%2C%20'type'%20%7C%20'id'%3E%3E%20%26%20%7B%20localChannelId%3A%20string%20%7D%3B%0D%0A%0D%0A%2F**%0D%0A%20*%20Create%20a%20NewChannel%20of%20the%20specified%20type%2C%20ready%20to%20hand%20off%20to%2C%20for%20example%2C%0D%0A%20*%20a%20react%20form%20which%20can%20fill%20it%20in%20with%20values%20and%20turn%20it%20into%20a%20real%20Channel.%0D%0A%20*%2F%0D%0Aexport%20function%20makeNewChannel%3CT%20extends%20ChannelType%3E(type%3A%20T)%3A%20NewChannel%3CChannelOfType%3CT%3E%3E%20%7B%0D%0A%20%20%20%20const%20localChannelId%20%3D%20%60blahblahblah%60%3B%0D%0A%20%20%20%20return%20%7B%20type%2C%20localChannelId%20%7D%3B%0D%0A%7D%0D%0A%0D%0A%2F%2F%20Here's%20the%20exciting%20bit%3A%0D%0A%0D%0Aconst%20newTextChannel%20%3D%20makeNewChannel('text')%3B%0D%0A%2F%2F%20Property%20'phoneNumber'%20does%20not%20exist%20on%20type%20'NewChannel%3CTextChannel%3E'.ts(2339)%0D%0AnewTextChannel.phoneNumber%20%3D%20'613-555-1234'%3B%0D%0A%0D%0Aconst%20newTextChannel2%20%3A%20NewChannel%3CTextChannel%3E%20%3D%20makeNewChannel('text')%3B%0D%0A%2F%2F%20But%20this%20works!%0D%0AnewTextChannel2.phoneNumber%20%3D%20'613-555-1234'%3B%0D%0A
https://github.com/jwalton
Jason Walton (jwalton)https://github.com/jwalton
on Mar 30, 2019https://github.com/microsoft/TypeScript/issues/30657#issuecomment-478201959
https://github.com/ahejlsberg
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on Mar 30, 2019https://github.com/microsoft/TypeScript/issues/30657#issuecomment-478255613
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
Wesley Wigham (weswigham)https://github.com/weswigham
on Mar 30, 2019https://github.com/microsoft/TypeScript/issues/30657#event-2241084163
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
on Mar 30, 2019https://github.com/microsoft/TypeScript/issues/30657#event-2241084222
https://github.com/weswigham
Wesley Wigham (weswigham)https://github.com/weswigham
on Apr 4, 2019https://github.com/microsoft/TypeScript/issues/30657#issuecomment-479706193
Wesley Wigham (weswigham)https://github.com/weswigham
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#30753https://github.com/microsoft/TypeScript/pull/30753
on Apr 16, 2019https://github.com/microsoft/TypeScript/issues/30657#event-2278226481
microsofthttps://github.com/microsoft
on Oct 21, 2025https://github.com/microsoft/TypeScript/issues/30657#event-20415930046
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/30657
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/30657
Wesley Wigham (weswigham)https://github.com/weswigham
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.