René's URL Explorer Experiment


Title: Tag types · Issue #4895 · microsoft/TypeScript · GitHub

Open Graph Title: Tag types · Issue #4895 · microsoft/TypeScript

X Title: Tag types · Issue #4895 · microsoft/TypeScript

Description: Problem There is no straight way to encode a predicate (some checking) about a value in its type. Details There are situations when a value has to pass some sort of check/validation prior to being used. For example: a min/max functions c...

Open Graph Description: Problem There is no straight way to encode a predicate (some checking) about a value in its type. Details There are situations when a value has to pass some sort of check/validation prior to being ...

X Description: Problem There is no straight way to encode a predicate (some checking) about a value in its type. Details There are situations when a value has to pass some sort of check/validation prior to being ...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Tag types","articleBody":"### Problem\n- There is no straight way to encode a predicate (some checking) about a value in its type.\n### Details\n\nThere are situations when a value has to pass some sort of check/validation prior to being used. For example: a min/max functions can only operate on a non-empty array so there must be a check if a given array has any elements. If we pass a plain array that might as well be empty, then we need to account for such case inside the min/max functions, by doing one of the following:\n- crashing\n- returning undefined\n- returning a given default value\n\nThis way the calling side has to deal with the consequences of min/max being called yet not being able to deliver.\n\n``` typescript\nfunction min\u003ca>(values: a[], isGreater: (one: a, another: a) => boolean) : a {\n   if (values.length \u003c 1) { throw Error('Array is empty.'); }\n   // ...\n}\nvar found;\ntry {\n   found = min([]);\n} catch (e) {\n   found = undefined;\n}\n```\n### Solution\n\nA better idea is to leverage the type system to rule out a possibility of the min function being called with an empty array. In order to do so we might consider so called tag types. \n\nA **tag type** is a qualifier type that indicates that some predicate about a value it is associated with holds true.\n\n``` typescript\n\nconst enum AsNonEmpty {} // a tag type that encodes that a check for being non-empty was passed\n\nfunction min\u003ca>(values: a[] & AsNonEmpty) : a {\n   // only values that are tagged with AsNonEmpty can be passed to this function\n   // the type system is responsible for enforcing this constraint\n   // a guarantee by the type system that only non-empty array will be passed makes\n   // implementation of this function simpler because only one main case needs be considered\n   // leaving empty-case situations outside of this function\n}\n\nmin([]); // \u003c-- compile error, tag is missing, the argument is not known to be non-empty\nmin([1, 2]); // \u003c-- compile error, tag is missing again, the argument is not know to be non-empty\n```\n\nit's up to the developer in what circumstances an array gets its AsNonEmpty tag, which can be something like:\n\n``` typescript\n// guarntee is given by the server, so we always trust the data that comes from it\ninterface GuaranteedByServer {\n    values: number[] & AsNonEmpty;\n}\n\n```\n\nAlso tags can be assigned at runtime:\n\n``` typescript\n\nfunction asNonEmpty(values: a[]) : (a[] & AsNonEmpty) | void {\n    return values.length > 0 ? \u003ca[] & AsNonEmpty> : undefined;\n}\n\nfunction isVoid\u003ca>(value: a | void) : value is void {\n  return value == null;\n}\n\nvar values = asNonEmpty(Math.random() > 0.5 ? [1, 2, 3] : []);\nif (isVoid(values)) {\n   // there are no  elements in the array, so we can't call min\n   var niceTry = min(values); // \u003c-- compile error; \n} else {\n    var found = min(values); // \u003c-- ok, tag is there, safe to call\n}\n\n```\n\nAs was shown in the current version (1.6) an empty const enum type can be used as a marker type (AsNonEmpty in the above example), because\n- enums might not have any members and yet be different from the empty type\n- enums are branded (not assignable to one another)\n\nHowever enums have their limitations:\n- enum is assignable by numbers\n- enum cannot hold a type parameter\n- enum cannot have members\n\nA few more examples of what tag type can encode:\n- `string & AsTrimmed & AsLowerCased & AsAtLeast3CharLong`\n- `number & AsNonNegative & AsEven`\n- `date & AsInWinter & AsFirstDayOfMonth`\n\nCustom types can also be augmented with tags. This is especially useful when the types are defined outside of the project and developers can't alter them.\n- `User & AsHavingClearance`\n\n**ALSO NOTE**: In a way tag types are similar to boolean properties (flags), BUT they get type-erased and carry no rutime overhead whatsoever being a good example of a zero-cost abstraction.\n\n**UPDATED:**\n\nAlso tag types can be used as units of measure in a way:\n- `string & AsEmail`, `string & AsFirstName`:\n\n``` typescript\n\nvar email = \u003cstring & AsEmail> 'aleksey.bykov@yahoo.com';\nvar firstName = \u003cstring & AsFirstName> 'Aleksey';\nfirstName = email; // \u003c-- compile error\n```\n- `number & In\u003cMhz>`, `number & In\u003cPx>`:\n\n``` typescript\n\nvar freq = \u003cnumber & In\u003cMhz>> 12000;\nvar width =   \u003cnumber & In\u003cPx>> 768;\nfreq = width; // \u003c-- compile error\n\nfunction divide\u003ca, b>(left: number & In\u003ca>, right: number & In\u003cb> & AsNonZero) : number & In\u003cRatio\u003ca, b>> {\n     return \u003cnumber & In\u003cRatio\u003ca, b>>> left  / right;\n}\n\nvar ratio = divide(freq, width); // \u003c-- number & In\u003cRatio\u003cMhz, Px>>\n\n```\n\n```\n```\n","author":{"url":"https://github.com/zpdDG4gta8XKpMCd","@type":"Person","name":"zpdDG4gta8XKpMCd"},"datePublished":"2015-09-21T09:47:25Z","url":"https://github.com/microsoft/TypeScript/issues/4895"}

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:6944dc36-ab77-c8ae-2fc8-02a6b56a8f34
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE414:2DBD56:12A586:19782D:6AFBFB94
html-safe-nonce2234a4b347dd24abbcca983cb824101b46f46b33401d7c9cbb71e27996e2c6e5
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNDE0OjJEQkQ1NjoxMkE1ODY6MTk3ODJEOjZBRkJGQjk0IiwidmlzaXRvcl9pZCI6IjM2NjU2Mjc4MTg2NzYxOTAxMDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac9abe30a2baeee354282fa062706c10628dc1cb355b1e1425da8c1f586ef4012e
hovercard-subject-tagissue:107477907
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/4895/issue_layout
twitter:imagehttps://opengraph.githubassets.com/239d8c5ba858689216895a9931ce3009af0ba50a8da3a863ea9f901403672331/microsoft/TypeScript/issues/4895
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/239d8c5ba858689216895a9931ce3009af0ba50a8da3a863ea9f901403672331/microsoft/TypeScript/issues/4895
og:image:altProblem There is no straight way to encode a predicate (some checking) about a value in its type. Details There are situations when a value has to pass some sort of check/validation prior to being ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamezpdDG4gta8XKpMCd
hostnamegithub.com
expected-hostnamegithub.com
Nonefa74413a1d84dac536fcca0740780bcbd3207bafec0e51873b73ff8e8cca032f
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
releaseb3b5633a74535d9c23385512d534c66c8fde1907
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/4895#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F4895
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%2F4895
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/4895
Reloadhttps://github.com/microsoft/TypeScript/issues/4895
Reloadhttps://github.com/microsoft/TypeScript/issues/4895
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests335 (335)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/pulse
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/4895
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/4895
Tag typeshttps://github.com/microsoft/TypeScript/issues/4895#top
DiscussionIssues which may not have code impacthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Discussion%22
https://github.com/zpdDG4gta8XKpMCd
ZpdDG4gta (zpdDG4gta8XKpMCd)https://github.com/zpdDG4gta8XKpMCd
on Sep 21, 2015https://github.com/microsoft/TypeScript/issues/4895#issue-107477907
Nexthttps://github.com/microsoft/TypeScript/issues/4895?timeline_page=1
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Sep 22, 2015https://github.com/microsoft/TypeScript/issues/4895#issuecomment-142428454
https://github.com/Microsoft/TypeScript/blob/master/src/compiler/types.ts#L485https://github.com/Microsoft/TypeScript/blob/master/src/compiler/types.ts#L485
#1003https://github.com/microsoft/TypeScript/issues/1003
#202https://github.com/microsoft/TypeScript/issues/202
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
DiscussionIssues which may not have code impacthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Discussion%22
on Sep 22, 2015https://github.com/microsoft/TypeScript/issues/4895#event-416371722
https://github.com/zpdDG4gta8XKpMCd
ZpdDG4gta (zpdDG4gta8XKpMCd)https://github.com/zpdDG4gta8XKpMCd
on Sep 24, 2015https://github.com/microsoft/TypeScript/issues/4895#issuecomment-142952722
https://github.com/jovdb
Van den Berghe Jo (jovdb)https://github.com/jovdb
on Oct 5, 2016https://github.com/microsoft/TypeScript/issues/4895#issuecomment-251650130
https://github.com/mindplay-dk
Rasmus Schultz (mindplay-dk)https://github.com/mindplay-dk
on Apr 7, 2018https://github.com/microsoft/TypeScript/issues/4895#issuecomment-379451119
https://github.com/mindplay-dk
Rasmus Schultz (mindplay-dk)https://github.com/mindplay-dk
on Apr 15, 2018https://github.com/microsoft/TypeScript/issues/4895#issuecomment-381414874
https://github.com/ethanfrey
Ethan Frey (ethanfrey)https://github.com/ethanfrey
on Apr 27, 2018https://github.com/microsoft/TypeScript/issues/4895#issuecomment-384939441
Aleksey-Bykovhttps://github.com/Aleksey-Bykov
https://www.idris-lang.org/example/https://www.idris-lang.org/example/
Rasmus Schultz (@mindplay-dk)https://github.com/mindplay-dk
https://github.com/dgreensp
David Greenspan (dgreensp)https://github.com/dgreensp
on Apr 29, 2018https://github.com/microsoft/TypeScript/issues/4895#issuecomment-385264209
Ethan Frey (@ethanfrey)https://github.com/ethanfrey
https://github.com/mindplay-dk
Rasmus Schultz (mindplay-dk)https://github.com/mindplay-dk
on Apr 30, 2018https://github.com/microsoft/TypeScript/issues/4895#issuecomment-385326444
Ethan Frey (@ethanfrey)https://github.com/ethanfrey
David Greenspan (@dgreensp)https://github.com/dgreensp
Simon Meskens (@SimonMeskens)https://github.com/SimonMeskens
herehttps://github.com/Microsoft/TypeScript/issues/202#issuecomment-381603738
https://github.com/SimonMeskens
Simon Meskens (SimonMeskens)https://github.com/SimonMeskens
on Apr 30, 2018https://github.com/microsoft/TypeScript/issues/4895#issuecomment-385327835
Ethan Frey (@ethanfrey)https://github.com/ethanfrey
https://github.com/tycho01/typicalhttps://github.com/tycho01/typical
https://github.com/ethanfrey
Ethan Frey (ethanfrey)https://github.com/ethanfrey
on Apr 30, 2018https://github.com/microsoft/TypeScript/issues/4895#issuecomment-385363780
David Greenspan (@dgreensp)https://github.com/dgreensp
Rasmus Schultz (@mindplay-dk)https://github.com/mindplay-dk
https://github.com/ethanfrey
Ethan Frey (ethanfrey)https://github.com/ethanfrey
on Apr 30, 2018https://github.com/microsoft/TypeScript/issues/4895#issuecomment-385364712
Simon Meskens (@SimonMeskens)https://github.com/SimonMeskens
https://github.com/tycho01/typical/blob/master/src/array/IncIndexNumbObj.tshttps://github.com/tycho01/typical/blob/master/src/array/IncIndexNumbObj.ts
https://github.com/gcanti/typelevel-ts#naturalshttps://github.com/gcanti/typelevel-ts#naturals
https://github.com/gcanti/typelevel-ts/blob/master/src/index.ts#L66-L77https://github.com/gcanti/typelevel-ts/blob/master/src/index.ts#L66-L77
https://ranjitjhala.github.io/static/refinement_types_for_typescript.pdfhttps://ranjitjhala.github.io/static/refinement_types_for_typescript.pdf
https://github.com/UCSD-PL/refscripthttps://github.com/UCSD-PL/refscript
https://github.com/dgreensp
David Greenspan (dgreensp)https://github.com/dgreensp
on Apr 30, 2018https://github.com/microsoft/TypeScript/issues/4895#issuecomment-385449364
Ethan Frey (@ethanfrey)https://github.com/ethanfrey
https://github.com/ethanfrey
Ethan Frey (ethanfrey)https://github.com/ethanfrey
on May 2, 2018https://github.com/microsoft/TypeScript/issues/4895#issuecomment-385980355
David Greenspan (@dgreensp)https://github.com/dgreensp
https://github.com/ForbesLindesay
Forbes Lindesay (ForbesLindesay)https://github.com/ForbesLindesay
on May 3, 2018https://github.com/microsoft/TypeScript/issues/4895#issuecomment-386172299
https://github.com/qwerty2501
qwerty2501 (qwerty2501)https://github.com/qwerty2501
on Sep 1, 2018https://github.com/microsoft/TypeScript/issues/4895#issuecomment-417837762
Michael Busby (@ProdigySim)https://github.com/ProdigySim
Simon Meskens (@SimonMeskens)https://github.com/SimonMeskens
https://github.com/ProdigySim
Michael Busby (ProdigySim)https://github.com/ProdigySim
on Sep 25, 2018https://github.com/microsoft/TypeScript/issues/4895#issuecomment-424429077
Simon Meskens (@SimonMeskens)https://github.com/SimonMeskens
qwerty2501 (@qwerty2501)https://github.com/qwerty2501
https://github.com/qwerty2501
qwerty2501 (qwerty2501)https://github.com/qwerty2501
on Sep 26, 2018https://github.com/microsoft/TypeScript/issues/4895#issuecomment-424796185
Michael Busby (@ProdigySim)https://github.com/ProdigySim
https://github.com/ProdigySim
Michael Busby (ProdigySim)https://github.com/ProdigySim
on Sep 27, 2018https://github.com/microsoft/TypeScript/issues/4895#issuecomment-425132582
how Flow handles opaque typeshttps://flow.org/en/docs/types/opaque-types/
Simon Meskens (@SimonMeskens)https://github.com/SimonMeskens
typescript playground link demonstrating different constructions of Opaquehttp://www.typescriptlang.org/play/#src=type%20OpaqueTag%3CS%20extends%20string%3E%20%3D%20%7B%0D%0A%20%20%20%20readonly%20__tag%3A%20S%0D%0A%7D%0D%0A%0D%0Atype%20SuperOpaque%3CS%20extends%20string%3E%20%3D%20OpaqueTag%3CS%3E%3B%0D%0Atype%20WeakOpaque%3CT%2C%20S%20extends%20string%3E%20%3D%20T%20%26%20OpaqueTag%3CS%3E%3B%0D%0Atype%20StrongOpaque%3CT%2C%20S%20extends%20string%3E%20%3D%20WeakOpaque%3CT%2C%20S%3E%20%7C%20SuperOpaque%3CS%3E%3B%0D%0A%0D%0A%0D%0Afunction%20takesStr(str%3A%20string)%20%7B%0D%0A%20%20%20%20console.log(str)%3B%0D%0A%7D%0D%0A%0D%0Atype%20WeakA%20%3D%20WeakOpaque%3Cstring%2C%20'weak_aye'%3E%3B%0D%0Atype%20WeakB%20%3D%20WeakOpaque%3Cstring%2C%20'weak_bee'%3E%3B%0D%0A%0D%0Aconst%20weakA%3A%20WeakA%20%3D%20'weak%20a'%20as%20WeakA%3B%0D%0Alet%20weakB%3A%20WeakB%20%3D%20'weak%20b'%20as%20WeakB%3B%0D%0A%0D%0Atype%20StrongA%20%3D%20StrongOpaque%3Cstring%2C%20'strong_aye'%3E%3B%0D%0Atype%20StrongB%20%3D%20StrongOpaque%3Cstring%2C%20'strong_bee'%3E%3B%0D%0A%0D%0Aconst%20strongA%3A%20StrongA%20%3D%20'strong%20a'%20as%20StrongA%3B%0D%0Alet%20strongB%3A%20StrongB%20%3D%20'strong%20b'%20as%20StrongB%3B%0D%0A%0D%0A%0D%0Atype%20SuperA%20%3D%20SuperOpaque%3C'super_aye'%3E%3B%0D%0Atype%20SuperB%20%3D%20SuperOpaque%3C'super_bee'%3E%3B%0D%0A%0D%0Aconst%20superA%3A%20SuperA%20%3D%20'super%20a'%20as%20any%20as%20SuperA%3B%0D%0Alet%20superB%3A%20SuperB%20%3D%20'super%20b'%20as%20any%20as%20SuperB%3B%0D%0A%0D%0A%0D%0A%2F%2F%0D%0A%2F%2F%20Assignment%20between%20unrelated%20opaque%20types%0D%0A%2F%2F%0D%0A%2F%2F%20Errors%20correctly%3A%0D%0AweakB%20%3D%20weakA%3B%0D%0AstrongA%20%3D%20strongB%3B%0D%0AsuperB%20%3D%20superA%3B%0D%0A%0D%0A%2F%2F%0D%0A%2F%2F%20Casting%20to%20a%20non-underlying%20type%0D%0A%2F%2F%0D%0A%2F%2F%20Errors%20correctly%3A%0D%0Aconst%20n1%20%3D%20weakA%20as%20number%3B%0D%0Aconst%20n2%20%3D%20strongA%20as%20number%3B%0D%0Aconst%20n3%20%3D%20superA%20as%20number%3B%0D%0A%2F%2F%20reinterperet%20cast%20still%20works%0D%0Aconst%20n4%20%3D%20superA%20as%20any%20as%20number%3B%0D%0A%0D%0A%2F%2F%0D%0A%2F%2F%20Using%20the%20opaque%20type%20as%20an%20argument%20of%20the%20underlying%20type%0D%0A%2F%2F%0D%0AtakesStr(weakA)%3B%0D%0AtakesStr(strongA%20as%20string)%3B%0D%0AtakesStr(superA%20as%20any%20as%20string)%3B%0D%0A%2F%2F%20Errors%3A%0D%0AtakesStr(strongA)%3B%0D%0AtakesStr(superA)%3B%0D%0AtakesStr(superA%20as%20string)%3B%0D%0A%0D%0A%0D%0A%2F%2F%0D%0A%2F%2F%20Use%20of%20opaque%20type%20as%20an%20index%20type%0D%0A%2F%2F%0D%0A%2F%2F%20Errors%20unfortunately%3A%0D%0Aconst%20obj_weak%3A%20%7B%20%5Bidx%3A%20WeakA%5D%3A%20number%20%7D%20%3D%20%7B%7D%3B%0D%0Aconst%20obj_strong%3A%20%7B%20%5Bidx%3A%20StrongA%5D%3A%20number%20%7D%20%3D%20%7B%7D%3B%0D%0Aconst%20obj_super%3A%20%7B%20%5Bidx%3A%20SuperA%5D%3A%20number%20%7D%20%3D%20%7B%7D%3B%0D%0A%0D%0A%2F%2F%0D%0A%2F%2F%20Use%20of%20opaque%20type%20as%20Record%3CT%3E%20parameter%0D%0A%2F%2F%0D%0A%2F%2F%20DANGEROUS!%20allows%20any%20string!!!%0D%0Aconst%20weak_record%3A%20Record%3CWeakA%2C%20number%3E%20%3D%20%7B%7D%3B%0D%0Aweak_record%5BweakA%5D%20%3D%201234%3B%0D%0Aweak_record%5BweakB%5D%20%3D%2023423%3B%0D%0Aweak_record%5B'asdfa32r2'%5D%20%3D%20523%3B%0D%0A%2F%2F%20Errors%3A%0D%0Aconst%20strong_record%3A%20Record%3CStrongA%2C%20number%3E%20%3D%20%7B%7D%3B%0D%0Aconst%20super_record%3A%20Record%3CSuperA%2C%20number%3E%20%3D%20%7B%7D%3B%0D%0A%0D%0A%2F%2F%0D%0A%2F%2F%20Use%20of%20Opaque%3Cstring%2C%20S%3E%20type%20to%20index%20a%20Record%3Cstring%2C%20T%3E%0D%0A%2F%2F%0D%0Aconst%20record%3A%20Record%3Cstring%2C%20number%3E%20%3D%20%7B%0D%0A%20%20%20%20%5BweakA%5D%3A%20123%2C%0D%0A%20%20%20%20%5BstrongA%20as%20string%5D%3A%20124%2C%0D%0A%20%20%20%20%5BstrongA%20as%20any%20as%20string%5D%3A%20125%2C%0D%0A%20%20%20%20%2F%2F%20Errors%3A%0D%0A%20%20%20%20%5BstrongA%5D%3A%20123%2C%0D%0A%20%20%20%20%5BsuperA%5D%3A%20123%2C%0D%0A%20%20%20%20%5BsuperA%20as%20string%5D%3A%20124%2C%0D%0A%7D%3B%0D%0A%0D%0A%0D%0A
https://github.com/MicahZoltu
Micah Zoltu (MicahZoltu)https://github.com/MicahZoltu
on Nov 2, 2018https://github.com/microsoft/TypeScript/issues/4895#issuecomment-435541988
herehttps://github.com/Microsoft/TypeScript/issues/202#issuecomment-429578149
https://github.com/StephanSchmidt
Stephan Schmidt (StephanSchmidt)https://github.com/StephanSchmidt
on Mar 16, 2019https://github.com/microsoft/TypeScript/issues/4895#issuecomment-473513134
https://github.com/StephanSchmidt/taghirohttps://github.com/StephanSchmidt/taghiro
https://github.com/qwerty2501
qwerty2501 (qwerty2501)https://github.com/qwerty2501
on Jun 7, 2019https://github.com/microsoft/TypeScript/issues/4895#issuecomment-499989293
Michael Busby (@ProdigySim)https://github.com/ProdigySim
Greg Hurrell (wincent)https://github.com/wincent
on Aug 12, 2019https://github.com/microsoft/TypeScript/issues/4895#event-2551619533
refactor: make UUID an "opaque" typehttps://github.com/wincent/corpus/commit/bec398f2838b1e0f9dec8526f0c816b10819e7a7
bec398fhttps://github.com/wincent/corpus/commit/bec398f2838b1e0f9dec8526f0c816b10819e7a7
https://github.com/mtaran-google
mtaran-googlehttps://github.com/mtaran-google
on Aug 30, 2019https://github.com/microsoft/TypeScript/issues/4895#issuecomment-526711628
#4895 (comment)https://github.com/microsoft/TypeScript/issues/4895#issuecomment-401058832
#4895 (comment)https://github.com/microsoft/TypeScript/issues/4895#issuecomment-401067935
https://github.com/thehappycoder
Anton Kuzmin (thehappycoder)https://github.com/thehappycoder
on Jan 24, 2020https://github.com/microsoft/TypeScript/issues/4895#issuecomment-577972176
Stephan Schmidt (@StephanSchmidt)https://github.com/StephanSchmidt
https://github.com/mindplay-dk
Rasmus Schultz (mindplay-dk)https://github.com/mindplay-dk
on Mar 16, 2021https://github.com/microsoft/TypeScript/issues/4895#issuecomment-800163776
Wesley Wigham (@weswigham)https://github.com/weswigham
Mohamed Hegazy (@mhegazy)https://github.com/mhegazy
Wesley Wigham (@weswigham)https://github.com/weswigham
https://github.com/weswigham
Wesley Wigham (weswigham)https://github.com/weswigham
on Mar 16, 2021https://github.com/microsoft/TypeScript/issues/4895#issuecomment-800417762
https://github.com/beeplin
Beep LIN (beeplin)https://github.com/beeplin
on Jul 21, 2021https://github.com/microsoft/TypeScript/issues/4895#issuecomment-883906276
Wesley Wigham (@weswigham)https://github.com/weswigham
https://github.com/shicks
Stephen Hicks (shicks)https://github.com/shicks
on Mar 17, 2023https://github.com/microsoft/TypeScript/issues/4895#issuecomment-1473087127
Wesley Wigham (@weswigham)https://github.com/weswigham
#33290https://github.com/microsoft/TypeScript/pull/33290
shicks/TypeScript:structural-taghttps://github.com/shicks/TypeScript/tree/structural-tag
librarieshttps://github.com/kourge/ts-brand
numeroushttps://dev.to/andercodes/typescript-tip-safer-functions-with-branded-types-14o4
blogshttps://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d
TypeScripthttps://github.com/microsoft/TypeScript/blob/b8c71685f910230a9dca864d403e370a27ea1041/src/compiler/types.ts#L23
codebasehttps://github.com/microsoft/TypeScript/blob/b8c71685f910230a9dca864d403e370a27ea1041/src/compiler/corePublic.ts#L19
itselfhttps://github.com/microsoft/TypeScript/blob/b8c71685f910230a9dca864d403e370a27ea1041/src/compiler/builder.ts#L877
doesn't actually existhttps://www.typescriptlang.org/play#code/GYVwdgxgLglg9mABAQwM6oKYCcoDkMBu2AFMlgOYBciYh2AlIgN4CwAUIp4lABZZwB3GhiEBRLPyzEA5Kh5wQAGwAmwolkRYMyCD0Q9sGAITT6AbnYBfduygBPAA4ZEAISzIwqgLzMARu89qAjgYZUsLNnZlDAhFMmcIBFQoRAAPamSsGDByADI3D2UImGBEGX9C6URstMZWDi4AekbEABUAZW4ebIBrVEQBZ3IMFIMtABpEXxAUwcRlBGkoK0QMRUxmdi4UdGw8OilU80RmxCNzqyA
assumes it's an objecthttps://www.typescriptlang.org/play#code/GYVwdgxgLglg9mABAQwM6oKYCcoDkMBu2AFMlgOYBciYh2AlIgN4CwAUIp4lABZZwB3GhiEBRLPyzEA5Kh5wQAGwAmwolkRYMyCD0Q9sGAITT6AbnYBfduygBPAA4ZEAISzIwqgLzMARu89qAjgYZUsLNnZlDAhFMmcIBFQoRAAPajcPZQiYYERieyc4PNTEL3LEaThfACsYqFNmdi5EAHpWxAAVAGVuHhgwAGtURAFncgwUgy0AGkRfEBSxxGUEaSgrRAxFTCaOLjRMHHx1YlTzNo6ja6sgA
#33038https://github.com/microsoft/TypeScript/pull/33038
#202https://github.com/microsoft/TypeScript/issues/202
#202https://github.com/microsoft/TypeScript/issues/202
impossible to accurately usehttps://www.typescriptlang.org/play?target=7#code/GYVwdgxgLglg9mABCAzgUwDwBUB8AKAQwCcBzALkSwEoKA3OGAE0QG8BfAWAChuoBPAA5pEAZQLA0AIRgkYYKIgC8rAPoqU4qTLlQ6DRmwDc3bqEiwEiAO5ECA6bPmFSFFFCJySAHwBG2+TSimg46rNyIEYgwwIh4-EJwMcQkSorKAORuHmAk6YgAZPmIAIQA9AAMXgC0APwA2gCMVQCcALoAOowAVKUAdFBobs4kVFSIUAAWRHBWiOnpxlyRiERoUCBESMmIBCjIYADWYDNbe2ISIfKLnFxm0PBIGhJYcCLunsMU51qOUIFZnjCS0iq3Wm1E7xywyo11M4HulieaBelygnyCF38fwofl+QOWoI2SAcAEknNtdvsjicdnsATlfFiYdwbtxGGgIAAbYjCCAINyIAAerkh3m+qMW0Vi8TQiSFqQy9NyYxY4UipVKiAAEgQwIxOcJJsJjmAqrjQhBdsIJmhVr17WqIhrEJIQApOTAoFADYhGHBrMIUKghNBxhMYHs+SBOcw3DBOZzED5hAQMT8dMVHch0BglfhBcyuGxEGhOeh8erNeKsYhLegADSIASrIMAWwIPk5fEQVSTboDO05qwIjG7E11+rQsbgrbQWeddcGPZ2euscCIDcoIjDcgOe09mRXiDgPgAVhyFMcrJngRFUJgT+foPnCzcgA
#202https://github.com/microsoft/TypeScript/issues/202
#33290https://github.com/microsoft/TypeScript/pull/33290
rebase of ithttps://github.com/shicks/TypeScript/tree/structural-tag
https://github.com/Pyrolistical
Pyrolisticalhttps://github.com/Pyrolistical
on Nov 15, 2023https://github.com/microsoft/TypeScript/issues/4895#issuecomment-1813380007
zod .brandhttps://github.com/colinhacks/zod#brand
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/4895
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/4895
DiscussionIssues which may not have code impacthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Discussion%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.