René's URL Explorer Experiment


Title: Allow type parameters in base class expressions · Issue #26542 · microsoft/TypeScript · GitHub

Open Graph Title: Allow type parameters in base class expressions · Issue #26542 · microsoft/TypeScript

X Title: Allow type parameters in base class expressions · Issue #26542 · microsoft/TypeScript

Description: Search Terms typescript type parameters in base class expressions Suggestion Type parameters in base class expressions. Use Cases and Examples Let's start with a simple mixin [playground] (borrowed from proposal #13743): type Constructor...

Open Graph Description: Search Terms typescript type parameters in base class expressions Suggestion Type parameters in base class expressions. Use Cases and Examples Let's start with a simple mixin [playground] (borrowed...

X Description: Search Terms typescript type parameters in base class expressions Suggestion Type parameters in base class expressions. Use Cases and Examples Let's start with a simple mixin [playground] (borr...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow type parameters in base class expressions","articleBody":"## Search Terms\r\n\r\ntypescript type parameters in base class expressions\r\n\r\n## Suggestion\r\n\r\nType parameters in base class expressions.\r\n\r\n## Use Cases and Examples\r\n\r\nLet's start with a simple mixin [[playground]](https://www.typescriptlang.org/play/#src=type%20Constructor%3CT%20%3D%20%7B%7D%3E%20%3D%20new%20(...args%3A%20any%5B%5D)%20%3D%3E%20T%3B%0D%0A%0D%0Aclass%20Point%20%7B%0D%0A%20%20constructor(%0D%0A%20%20%20%20public%20readonly%20x%3A%20number%2C%0D%0A%20%20%20%20public%20readonly%20y%3A%20number%2C%0D%0A%20%20)%20%7B%7D%0D%0A%7D%0D%0A%0D%0Aconst%20Tagged%20%3D%20%3CT%2C%20B%20extends%20Constructor%20%3D%20B%3E(Base%3A%20B)%20%3D%3E%0D%0A%20%20class%20extends%20Base%20%7B%0D%0A%20%20%20%20getTag()%3A%20T%20%7B%0D%0A%20%20%20%20%20%20%2F%2F%20Just%20imagine%20I%20have%20a%20function%20that%20returns%20objects%2C%0D%0A%20%20%20%20%20%20%2F%2F%20and%20I%20want%20to%20case%20them%20to%20T.%0D%0A%20%20%20%20%20%20return%20%7B%7D%20as%20T%0D%0A%20%20%20%20%7D%0D%0A%20%20%7D%0D%0A%0D%0Aclass%20TaggedPoint%20extends%20Tagged(Point)%20%7B%7D) (borrowed from proposal #13743):\r\n\r\n```typescript\r\ntype Constructor\u003cT = {}> = new (...args: any[]) => T;\r\n\r\nclass Point {\r\n  constructor(\r\n    public readonly x: number,\r\n    public readonly y: number,\r\n  ) {}\r\n}\r\n\r\n// Tagged is a mixin with a type parameter.\r\nconst Tagged = \u003cT, B extends Constructor = B>(Base: B) =>\r\n  class extends Base {\r\n    getTag(): T {\r\n      // Just imagine I have a function that returns objects,\r\n      // and I want to case them to T.\r\n      return {} as T\r\n    }\r\n  }\r\n\r\nclass TaggedPoint extends Tagged(Point) {}\r\n```\r\n\r\nNow [if I want to specify the type argument for `Tagged`](https://stackoverflow.com/questions/48492002/passing-generic-types-through-to-mixins-in-typescript), that's easy enough [^1] [[playground]](https://www.typescriptlang.org/play/#src=type%20Constructor%3CT%20%3D%20%7B%7D%3E%20%3D%20new%20(...args%3A%20any%5B%5D)%20%3D%3E%20T%3B%0D%0A%0D%0Aclass%20Point%20%7B%0D%0A%20%20constructor(%0D%0A%20%20%20%20public%20readonly%20x%3A%20number%2C%0D%0A%20%20%20%20public%20readonly%20y%3A%20number%2C%0D%0A%20%20)%20%7B%7D%0D%0A%7D%0D%0A%0D%0Aconst%20Tagged%20%3D%20%3CT%2C%20B%20extends%20Constructor%20%3D%20B%3E(Base%3A%20B)%20%3D%3E%0D%0A%20%20class%20extends%20Base%20%7B%0D%0A%20%20%20%20getTag()%3A%20T%20%7B%0D%0A%20%20%20%20%20%20%2F%2F%20Just%20imagine%20I%20have%20a%20function%20that%20returns%20objects%2C%0D%0A%20%20%20%20%20%20%2F%2F%20and%20I%20want%20to%20case%20them%20to%20T.%0D%0A%20%20%20%20%20%20return%20%7B%7D%20as%20T%0D%0A%20%20%20%20%7D%0D%0A%20%20%7D%0D%0A%0D%0Aclass%20TaggedPoint%20extends%20Tagged%3Cnumber%3E(Point)%20%7B%7D):\r\n\r\n```typescript\r\nclass TaggedPoint extends Tagged\u003cnumber>(Point) {}\r\n```\r\n\r\nBut if I want to pass a derived class's type parameter as that argument, I cannot [[playground]](https://www.typescriptlang.org/play/#src=type%20Constructor%3CT%20%3D%20%7B%7D%3E%20%3D%20new%20(...args%3A%20any%5B%5D)%20%3D%3E%20T%3B%0D%0A%0D%0Aclass%20Point%20%7B%0D%0A%20%20constructor(%0D%0A%20%20%20%20public%20readonly%20x%3A%20number%2C%0D%0A%20%20%20%20public%20readonly%20y%3A%20number%2C%0D%0A%20%20)%20%7B%7D%0D%0A%7D%0D%0A%0D%0Aconst%20Tagged%20%3D%20%3CT%2C%20B%20extends%20Constructor%20%3D%20B%3E(Base%3A%20B)%20%3D%3E%0D%0A%20%20class%20extends%20Base%20%7B%0D%0A%20%20%20%20getTag()%3A%20T%20%7B%0D%0A%20%20%20%20%20%20%2F%2F%20Just%20imagine%20I%20have%20a%20function%20that%20returns%20objects%2C%0D%0A%20%20%20%20%20%20%2F%2F%20and%20I%20want%20to%20case%20them%20to%20T.%0D%0A%20%20%20%20%20%20return%20%7B%7D%20as%20T%0D%0A%20%20%20%20%7D%0D%0A%20%20%7D%0D%0A%0D%0Aclass%20UsesTheTag%3CT%3E%20extends%20Tagged%3CT%3E(Point)%20%7B%0D%0A%2F%2F%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5E%0D%0A%2F%2F%20error%3A%20Base%20class%20expressions%20cannot%20reference%0D%0A%2F%2F%20class%20type%20parameters.%0D%0A%20%20useTag()%3A%20T%20%7B%0D%0A%20%20%20%20const%20tag%3A%20T%20%3D%20this.getTag()%0D%0A%20%20%20%20return%20tag%0D%0A%20%20%7D%0D%0A%7D):\r\n\r\n```typescript\r\nclass UsesTheTag\u003cT> extends Tagged\u003cT>(Point) {\r\n//                                 ^\r\n// error: Base class expressions cannot reference\r\n// class type parameters.\r\n  useTag() {\r\n    const tag: T = this.getTag()\r\n  }\r\n}\r\n```\r\n\r\n[^1]: Note, this requires the default type argument `= B` shown above, but I have never seen it used in documentation, Stack Overflow, or blogs on the issue of TypeScript mixins. Is that because TypeScript is not actually deducing the type parameter from the function argument?\r\n\r\n## Checklist\r\n\r\nMy suggestion meets these guidelines:\r\n* [x] This wouldn't be a breaking change in existing TypeScript / JavaScript code\r\n* [x] This wouldn't change the runtime behavior of existing JavaScript code\r\n* [x] This could be implemented without emitting different JS based on the types of the expressions\r\n* [x] This isn't a runtime feature (e.g. new expression-level syntax)\r\n\r\n","author":{"url":"https://github.com/thejohnfreeman","@type":"Person","name":"thejohnfreeman"},"datePublished":"2018-08-19T22:35:18Z","url":"https://github.com/microsoft/TypeScript/issues/26542"}

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:bc9258d9-de1c-f3ec-6632-823f0d6ba1f5
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC7A4:10D9F8:6A8864:8F1ED6:6B00D48C
html-safe-nonceef5ab2605673bd612a10d9c501296ddf4cf86c993d513eab8e65b439591cc131
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDN0E0OjEwRDlGODo2QTg4NjQ6OEYxRUQ2OjZCMDBENDhDIiwidmlzaXRvcl9pZCI6IjI2ODQ5Mzg4OTYzOTA4MDQ2MjAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacf2432c6e7dfd24ad70ca50d3e388731e93db17eb51a001a141af3f07f6f55532
hovercard-subject-tagissue:351940497
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/26542/issue_layout
twitter:imagehttps://opengraph.githubassets.com/a94f0799be26a3f8f334add42bd7db4a9619a04ab1622a87aa6522067afa838d/microsoft/TypeScript/issues/26542
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/a94f0799be26a3f8f334add42bd7db4a9619a04ab1622a87aa6522067afa838d/microsoft/TypeScript/issues/26542
og:image:altSearch Terms typescript type parameters in base class expressions Suggestion Type parameters in base class expressions. Use Cases and Examples Let's start with a simple mixin [playground] (borrowed...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamethejohnfreeman
hostnamegithub.com
expected-hostnamegithub.com
Nonea481f62a1e04c9b9bdcb5628230682c66d59006f5b13b080f79cba84a176905b
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
release84c8c5cc25e2fb7f2308428458538436baecc6d2
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/26542#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F26542
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%2F26542
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/26542
Reloadhttps://github.com/microsoft/TypeScript/issues/26542
Reloadhttps://github.com/microsoft/TypeScript/issues/26542
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests307 (307)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/26542
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/26542
Allow type parameters in base class expressionshttps://github.com/microsoft/TypeScript/issues/26542#top
QuestionAn issue which isn't directly actionable in codehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Question%22
https://github.com/thejohnfreeman
John Freeman (thejohnfreeman)https://github.com/thejohnfreeman
on Aug 19, 2018https://github.com/microsoft/TypeScript/issues/26542#issue-351940497
[playground]https://www.typescriptlang.org/play/#src=type%20Constructor%3CT%20%3D%20%7B%7D%3E%20%3D%20new%20(...args%3A%20any%5B%5D)%20%3D%3E%20T%3B%0D%0A%0D%0Aclass%20Point%20%7B%0D%0A%20%20constructor(%0D%0A%20%20%20%20public%20readonly%20x%3A%20number%2C%0D%0A%20%20%20%20public%20readonly%20y%3A%20number%2C%0D%0A%20%20)%20%7B%7D%0D%0A%7D%0D%0A%0D%0Aconst%20Tagged%20%3D%20%3CT%2C%20B%20extends%20Constructor%20%3D%20B%3E(Base%3A%20B)%20%3D%3E%0D%0A%20%20class%20extends%20Base%20%7B%0D%0A%20%20%20%20getTag()%3A%20T%20%7B%0D%0A%20%20%20%20%20%20%2F%2F%20Just%20imagine%20I%20have%20a%20function%20that%20returns%20objects%2C%0D%0A%20%20%20%20%20%20%2F%2F%20and%20I%20want%20to%20case%20them%20to%20T.%0D%0A%20%20%20%20%20%20return%20%7B%7D%20as%20T%0D%0A%20%20%20%20%7D%0D%0A%20%20%7D%0D%0A%0D%0Aclass%20TaggedPoint%20extends%20Tagged(Point)%20%7B%7D
#13743https://github.com/microsoft/TypeScript/pull/13743
if I want to specify the type argument for Taggedhttps://stackoverflow.com/questions/48492002/passing-generic-types-through-to-mixins-in-typescript
1https://github.com/microsoft/TypeScript/issues/26542#user-content-fn-1-c0358a57548f6f309475e63d215eaffb
[playground]https://www.typescriptlang.org/play/#src=type%20Constructor%3CT%20%3D%20%7B%7D%3E%20%3D%20new%20(...args%3A%20any%5B%5D)%20%3D%3E%20T%3B%0D%0A%0D%0Aclass%20Point%20%7B%0D%0A%20%20constructor(%0D%0A%20%20%20%20public%20readonly%20x%3A%20number%2C%0D%0A%20%20%20%20public%20readonly%20y%3A%20number%2C%0D%0A%20%20)%20%7B%7D%0D%0A%7D%0D%0A%0D%0Aconst%20Tagged%20%3D%20%3CT%2C%20B%20extends%20Constructor%20%3D%20B%3E(Base%3A%20B)%20%3D%3E%0D%0A%20%20class%20extends%20Base%20%7B%0D%0A%20%20%20%20getTag()%3A%20T%20%7B%0D%0A%20%20%20%20%20%20%2F%2F%20Just%20imagine%20I%20have%20a%20function%20that%20returns%20objects%2C%0D%0A%20%20%20%20%20%20%2F%2F%20and%20I%20want%20to%20case%20them%20to%20T.%0D%0A%20%20%20%20%20%20return%20%7B%7D%20as%20T%0D%0A%20%20%20%20%7D%0D%0A%20%20%7D%0D%0A%0D%0Aclass%20TaggedPoint%20extends%20Tagged%3Cnumber%3E(Point)%20%7B%7D
[playground]https://www.typescriptlang.org/play/#src=type%20Constructor%3CT%20%3D%20%7B%7D%3E%20%3D%20new%20(...args%3A%20any%5B%5D)%20%3D%3E%20T%3B%0D%0A%0D%0Aclass%20Point%20%7B%0D%0A%20%20constructor(%0D%0A%20%20%20%20public%20readonly%20x%3A%20number%2C%0D%0A%20%20%20%20public%20readonly%20y%3A%20number%2C%0D%0A%20%20)%20%7B%7D%0D%0A%7D%0D%0A%0D%0Aconst%20Tagged%20%3D%20%3CT%2C%20B%20extends%20Constructor%20%3D%20B%3E(Base%3A%20B)%20%3D%3E%0D%0A%20%20class%20extends%20Base%20%7B%0D%0A%20%20%20%20getTag()%3A%20T%20%7B%0D%0A%20%20%20%20%20%20%2F%2F%20Just%20imagine%20I%20have%20a%20function%20that%20returns%20objects%2C%0D%0A%20%20%20%20%20%20%2F%2F%20and%20I%20want%20to%20case%20them%20to%20T.%0D%0A%20%20%20%20%20%20return%20%7B%7D%20as%20T%0D%0A%20%20%20%20%7D%0D%0A%20%20%7D%0D%0A%0D%0Aclass%20UsesTheTag%3CT%3E%20extends%20Tagged%3CT%3E(Point)%20%7B%0D%0A%2F%2F%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5E%0D%0A%2F%2F%20error%3A%20Base%20class%20expressions%20cannot%20reference%0D%0A%2F%2F%20class%20type%20parameters.%0D%0A%20%20useTag()%3A%20T%20%7B%0D%0A%20%20%20%20const%20tag%3A%20T%20%3D%20this.getTag()%0D%0A%20%20%20%20return%20tag%0D%0A%20%20%7D%0D%0A%7D
↩https://github.com/microsoft/TypeScript/issues/26542#user-content-fnref-1-c0358a57548f6f309475e63d215eaffb
https://github.com/mattmccutchen
Matt McCutchen (mattmccutchen)https://github.com/mattmccutchen
on Aug 20, 2018https://github.com/microsoft/TypeScript/issues/26542#issuecomment-414173688
playgroundhttps://www.typescriptlang.org/play/#src=type%20Constructor%3CT%20%3D%20%7B%7D%3E%20%3D%20new%20(...args%3A%20any%5B%5D)%20%3D%3E%20T%3B%0D%0A%0D%0Aclass%20Point%20%7B%0D%0A%20%20constructor(%0D%0A%20%20%20%20public%20readonly%20x%3A%20number%2C%0D%0A%20%20%20%20public%20readonly%20y%3A%20number%2C%0D%0A%20%20)%20%7B%7D%0D%0A%7D%0D%0A%0D%0Aconst%20Tagged%20%3D%20(Base%3A%20Constructor)%20%3D%3E%0D%0A%20%20class%20%3CT%3E%20extends%20Base%20%7B%0D%0A%20%20%20%20getTag()%3A%20T%20%7B%0D%0A%20%20%20%20%20%20%2F%2F%20Just%20imagine%20I%20have%20a%20function%20that%20returns%20objects%2C%0D%0A%20%20%20%20%20%20%2F%2F%20and%20I%20want%20to%20case%20them%20to%20T.%0D%0A%20%20%20%20%20%20return%20%7B%7D%20as%20T%0D%0A%20%20%20%20%7D%0D%0A%20%20%7D%3B%0D%0A%0D%0Aclass%20UsesTheTag%3CT%3E%20extends%20Tagged(Point)%3CT%3E%20%7B%0D%0A%20%20useTag()%3A%20T%20%7B%0D%0A%20%20%20%20const%20tag%3A%20T%20%3D%20this.getTag()%0D%0A%20%20%20%20return%20tag%0D%0A%20%20%7D%0D%0A%7D
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
QuestionAn issue which isn't directly actionable in codehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Question%22
on Aug 20, 2018https://github.com/microsoft/TypeScript/issues/26542#event-1796602419
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Aug 20, 2018https://github.com/microsoft/TypeScript/issues/26542#issuecomment-414174856
#26154https://github.com/microsoft/TypeScript/issues/26154
https://github.com/mattmccutchen
Matt McCutchen (mattmccutchen)https://github.com/mattmccutchen
on Aug 20, 2018https://github.com/microsoft/TypeScript/issues/26542#issuecomment-414175494
https://github.com/thejohnfreeman
John Freeman (thejohnfreeman)https://github.com/thejohnfreeman
on Aug 20, 2018https://github.com/microsoft/TypeScript/issues/26542#issuecomment-414176746
https://github.com/mattmccutchen
Matt McCutchen (mattmccutchen)https://github.com/mattmccutchen
on Aug 20, 2018https://github.com/microsoft/TypeScript/issues/26542#issuecomment-414320664
this approachhttps://github.com/Microsoft/TypeScript/issues/17829#issuecomment-323020591
https://github.com/thejohnfreeman
John Freeman (thejohnfreeman)https://github.com/thejohnfreeman
on Aug 20, 2018https://github.com/microsoft/TypeScript/issues/26542#issuecomment-414355965
playgroundhttps://www.typescriptlang.org/play/#src=type%20Constructor%3CT%20%3D%20%7B%7D%3E%20%3D%20new%20(...args%3A%20any%5B%5D)%20%3D%3E%20T%3B%0D%0A%0D%0Aclass%20Point%20%7B%0D%0A%20%20constructor(%0D%0A%20%20%20%20public%20readonly%20x%3A%20number%2C%0D%0A%20%20%20%20public%20readonly%20y%3A%20number%2C%0D%0A%20%20)%20%7B%7D%0D%0A%7D%0D%0A%0D%0Aconst%20Tagged%20%3D%20(Base%3A%20Constructor%3CPoint%3E)%20%3D%3E%0D%0A%20%20class%20%3CT%3E%20extends%20Base%20%7B%0D%0A%20%20%20%20getTag()%3A%20T%20%7B%0D%0A%20%20%20%20%20%20%2F%2F%20I%20can%20use%20the%20facilities%20of%20the%20base%20class%0D%0A%20%20%20%20%20%20%2F%2F%20(in%20this%20case%2C%20Point)%20because%20I%20declared%20that%20%60Base%60%0D%0A%20%20%20%20%20%20%2F%2F%20is%20a%20%60Constructor%60%20of%20that%20class.%0D%0A%20%20%20%20%20%20const%20x%3A%20number%20%3D%20this.x%0D%0A%20%20%20%20%20%20%2F%2F%20Constructions%20of%20my%20class%20assert%20the%20type%20that%20I%20return%2C%0D%0A%20%20%20%20%20%20%2F%2F%20so%20that%20they%20get%20type%20safety%20when%20working%20with%20the%0D%0A%20%20%20%20%20%20%2F%2F%20objects%20I%20return.%0D%0A%20%20%20%20%20%20return%20%7B%20tag%3A%20'it'%20%7D%20as%20any%20as%20T%0D%0A%20%20%20%20%7D%0D%0A%20%20%7D%3B%0D%0A%0D%0Aclass%20UsesTheTag%3CT%3E%20extends%20Tagged(Point)%3CT%3E%20%7B%0D%0A%20%20useTag()%3A%20T%20%7B%0D%0A%20%20%20%20%2F%2F%20I%20can%20use%20the%20facilities%20of%20the%20base%20class%20(Tagged)%0D%0A%20%20%20%20%2F%2F%20and%20*its*%20base%20class%20(Point).%0D%0A%20%20%20%20const%20tag%3A%20T%20%3D%20this.getTag()%0D%0A%20%20%20%20const%20x%3A%20number%20%3D%20this.x%0D%0A%20%20%20%20return%20tag%0D%0A%20%20%7D%0D%0A%7D%0D%0A%0D%0A%2F%2F%20When%20I%20construct%20an%20object%2C%20I%20declare%20the%20type%20that%20its%0D%0A%2F%2F%20%60getTag%60%20and%20%60useTag%60%20methods%20return.%0D%0Aconst%20tp%20%3D%20new%20UsesTheTag%3C%7B%20tag%3A%20string%20%7D%3E(1%2C%202)%0D%0A%2F%2F%20When%20I%20call%20%60getTag%60%20or%20%60useTag%60%2C%20TypeScript%20checks%20that%0D%0A%2F%2F%20I%20use%20the%20return%20value%20in%20accordance%20with%20the%20tag%20type%0D%0A%2F%2F%20I%20declared.%0D%0Aconst%20tag%20%3D%20tp.getTag()%0D%0Aconsole.log(tag.tag)%0D%0Aconst%20sameTag%20%3D%20tp.useTag()%0D%0Aconsole.log(tag.tag)%0D%0A%2F%2F%20%60tp%60%20should%20also%20be%20a%20Point.%20These%20should%20work%2C%20just%20as%20they%0D%0A%2F%2F%20did%20within%20the%20implementation%20of%20%60getTag%60%20and%20%60useTag%60.%0D%0Aconst%20x%3A%20number%20%3D%20tp.x%0D%0Aconst%20y%3A%20number%20%3D%20tp.y
playgroundhttps://www.typescriptlang.org/play/#src=type%20Constructor%3CT%20%3D%20%7B%7D%3E%20%3D%20new%20(...args%3A%20any%5B%5D)%20%3D%3E%20T%3B%0D%0A%0D%0A%2F%2F%20The%20base%20class.%0D%0Aclass%20Point%20%7B%0D%0A%20%20constructor%20(%0D%0A%20%20%20%20public%20readonly%20x%3A%20number%2C%0D%0A%20%20%20%20public%20readonly%20y%3A%20number%2C%0D%0A%20%20)%20%7B%7D%0D%0A%7D%0D%0A%0D%0A%2F%2F%20An%20extended%20base%20class%20with%20additional%20facilities.%0D%0Aclass%20WeightedPoint%20extends%20Point%20%7B%0D%0A%20%20public%20readonly%20weight%3A%20number%20%3D%201%0D%0A%7D%0D%0A%0D%0A%2F%2F%20My%20mixin%20just%20needs%20the%20facilities%20of%20the%20base%20class.%0D%0Aconst%20SummedSquared%20%3D%20(Base%3A%20Constructor%3CPoint%3E)%20%3D%3E%0D%0A%20%20class%20extends%20Base%20%7B%0D%0A%20%20%20%20getSumOfSquares()%3A%20number%20%7B%0D%0A%20%20%20%20%20%20return%20this.x%20*%20this.x%20%2B%20this.y%20*%20this.x%0D%0A%20%20%20%20%7D%0D%0A%20%20%7D%3B%0D%0A%0D%0A%2F%2F%20My%20final%20subtype%20expects%20the%20extended%20base%20class%0D%0A%2F%2F%20because%20it%20needs%20those%20additional%20facilities%2C%0D%0A%2F%2F%20but%20it%20also%20wants%20the%20mixin%20applied.%0D%0Aclass%20SummedSquaredWeightedPoint%20extends%20SummedSquared(WeightedPoint)%20%7B%0D%0A%20%20getWeightedSumOfSquares()%3A%20number%20%7B%0D%0A%20%20%20%20%2F%2F%20I%20want%20to%20use%20the%20facilities%20of%20the%20base%20class%20of%0D%0A%20%20%20%20%2F%2F%20the%20base%20class%20(%60WeightPointed%60)%2C%20but%20TypeScript%20only%0D%0A%20%20%20%20%2F%2F%20knows%20that%20the%20base%20class%20is%20a%20%60Point%60%20because%20that%20is%0D%0A%20%20%20%20%2F%2F%20what%20the%20mixin%20declared.%0D%0A%20%20%20%20return%20(%0D%0A%20%20%20%20%20%20this.x%20*%20this.x%20*%20this.weight%20%2B%0D%0A%20%20%20%20%20%20this.y%20*%20this.y%20*%20this.weight%0D%0A%20%20%20%20%20%20%2F%2F%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20~~~~~~%0D%0A%20%20%20%20%20%20%2F%2F%20error%3A%20Property%20'weight'%20does%20not%20exist%20on%20type%20'SummedSquaredWeightedPoint'.%0D%0A%20%20%20%20)%0D%0A%20%20%7D%0D%0A%7D
John Freeman (thejohnfreeman)https://github.com/thejohnfreeman
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Aug 20, 2018https://github.com/microsoft/TypeScript/issues/26542#event-1797999823
https://github.com/admosity
Adam (admosity)https://github.com/admosity
on Oct 12, 2018https://github.com/microsoft/TypeScript/issues/26542#issuecomment-429445976
John Freeman (@thejohnfreeman)https://github.com/thejohnfreeman
This playgroundhttps://www.typescriptlang.org/play/#src=type%20Constructor%3CT%20%3D%20%7B%7D%3E%20%3D%20new%20(...args%3A%20any%5B%5D)%20%3D%3E%20T%3B%0D%0A%0D%0A%2F%2F%20The%20base%20class.%0D%0Aclass%20Point%20%7B%0D%0A%20%20constructor%20(%0D%0A%20%20%20%20public%20readonly%20x%3A%20number%2C%0D%0A%20%20%20%20public%20readonly%20y%3A%20number%2C%0D%0A%20%20)%20%7B%7D%0D%0A%7D%0D%0A%0D%0A%2F%2F%20An%20extended%20base%20class%20with%20additional%20facilities.%0D%0Aclass%20WeightedPoint%20extends%20Point%20%7B%0D%0A%20%20public%20readonly%20weight%3A%20number%20%3D%201%0D%0A%7D%0D%0A%0D%0A%2F%2F%20My%20mixin%20just%20needs%20the%20facilities%20of%20the%20base%20class.%0D%0Aconst%20SummedSquared%20%3D%20%3CT%20extends%20Constructor%3CPoint%3E%3E(Base%3A%20T)%20%3D%3E%0D%0A%20%20class%20extends%20Base%20%7B%0D%0A%20%20%20%20getSumOfSquares()%3A%20number%20%7B%0D%0A%20%20%20%20%20%20return%20this.x%20*%20this.x%20%2B%20this.y%20*%20this.x%0D%0A%20%20%20%20%7D%0D%0A%20%20%7D%3B%0D%0A%0D%0A%2F%2F%20My%20final%20subtype%20expects%20the%20extended%20base%20class%0D%0A%2F%2F%20because%20it%20needs%20those%20additional%20facilities%2C%0D%0A%2F%2F%20but%20it%20also%20wants%20the%20mixin%20applied.%0D%0Aclass%20SummedSquaredWeightedPoint%20extends%20SummedSquared(WeightedPoint)%20%7B%0D%0A%20%20getWeightedSumOfSquares()%3A%20number%20%7B%0D%0A%20%20%20%20%2F%2F%20I%20want%20to%20use%20the%20facilities%20of%20the%20base%20class%20of%0D%0A%20%20%20%20%2F%2F%20the%20base%20class%20(%60WeightPointed%60)%2C%20but%20TypeScript%20only%0D%0A%20%20%20%20%2F%2F%20knows%20that%20the%20base%20class%20is%20a%20%60Point%60%20because%20that%20is%0D%0A%20%20%20%20%2F%2F%20what%20the%20mixin%20declared.%0D%0A%20%20%20%20return%20(%0D%0A%20%20%20%20%20%20this.x%20*%20this.x%20*%20this.weight%20%2B%0D%0A%20%20%20%20%20%20this.y%20*%20this.y%20*%20this.weight%0D%0A%20%20%20%20%20%20%2F%2F%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20~~~~~~%0D%0A%20%20%20%20%20%20%2F%2F%20error%3A%20Property%20'weight'%20does%20not%20exist%20on%20type%20'SummedSquaredWeightedPoint'.%0D%0A%20%20%20%20)%0D%0A%20%20%7D%0D%0A%7D
https://user-images.githubusercontent.com/4655972/46891407-bcbfa700-ce37-11e8-809e-17f464a9e0cf.png
https://user-images.githubusercontent.com/4655972/46891413-c3e6b500-ce37-11e8-9255-c52386e35004.png
https://github.com/aoi-umi
aoi-umihttps://github.com/aoi-umi
on Dec 3, 2018https://github.com/microsoft/TypeScript/issues/26542#issuecomment-443573717
https://user-images.githubusercontent.com/17681077/49350223-1e3e1c80-f6e9-11e8-9c65-76143a5b1b00.png
https://user-images.githubusercontent.com/17681077/49350245-34e47380-f6e9-11e8-80c7-cab45897bcd8.png
microsofthttps://github.com/microsoft
on Oct 21, 2025https://github.com/microsoft/TypeScript/issues/26542#event-20415774443
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/26542
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/26542
QuestionAn issue which isn't directly actionable in codehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Question%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.