René's URL Explorer Experiment


Title: 'Discarding Parameters' plus 'Duck Typing' makes every parameter optional? · Issue #9352 · microsoft/TypeScript · GitHub

Open Graph Title: 'Discarding Parameters' plus 'Duck Typing' makes every parameter optional? · Issue #9352 · microsoft/TypeScript

X Title: 'Discarding Parameters' plus 'Duck Typing' makes every parameter optional? · Issue #9352 · microsoft/TypeScript

Description: After reading the Comparing two functions section of the handbook I got myself pretty confused and concerned. I have an example below that I think (taken to the prepare-for-duck-typing-extreme) means I should code every class's method as...

Open Graph Description: After reading the Comparing two functions section of the handbook I got myself pretty confused and concerned. I have an example below that I think (taken to the prepare-for-duck-typing-extreme) mea...

X Description: After reading the Comparing two functions section of the handbook I got myself pretty confused and concerned. I have an example below that I think (taken to the prepare-for-duck-typing-extreme) mea...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"'Discarding Parameters' plus 'Duck Typing' makes every parameter optional?","articleBody":"After reading the [Comparing two functions](https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Type%20Compatibility.md#comparing-two-functions) section of the handbook I got myself pretty confused and concerned. I have an example below that I think (taken to the prepare-for-duck-typing-extreme) means I should code every class's method as if all of its parameters are optional (even though they're not defined as such).\n\n**TypeScript Version:** \n\n1.8.10 / next (1.9.0-dev.20160624-1.0)\n\n**Code**\n\n``` ts\n(function () { \"use strict\";\n\n\nclass C1 { one(...hi: string[]) { } }\nclass C2 { one(hi: string) { hi.length; } }\n\nfunction Test() {\n    const c2 = new C2();\n    const c2as1: C1 = c2;   // BAD assignment\n\n    // TypeError: Cannot read property 'length' of undefined\n    c2as1.one();            // BAD execution\n\n    // error TS2346: Supplied parameters do not match any signature of call target.\n    //c2.one();\n\n    // error TS2345: Argument of type 'undefined' is not assignable to parameter of type 'string'.\n    //                 Happens once you enable TypeScript 2.0's --strictNullChecks.\n    //c2as1.one(void 0);\n    //c2.one(void 0);\n}\n\n\n})();\n```\n\n**Actual behavior:** \n\nI have to remember to write **run-time** checking of `typeof hi === \"string\" ? hi.length : 0` instead of the simple/easy `hi.length` inside my `C2#one(hi: string)` method to prevent against a TypeError.\n\n**Expected behavior:**\n\nI'd love for there to be some way for TypeScript to stop the `BAD assignment` line above; maybe one that turns off 'discarding' parameters altogether?\n\nThe defense given for discarding parameters is a signature like `Array#forEach` -- where callers commonly omit the 2nd/3rd parameters to the `callbackfn`. That doesn't make sense to me though, why isn't the \u003ckbd>*.d.ts\u003c/kbd> for `Array#forEach` just defined as:\n\n``` ts\nforEach(callbackfn: (value?: T, index?: number, array?: T[]) => void, thisArg?: any): void;\n```\n\nInstead of how it is?\n\n``` ts\nforEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void;\n```\n\nMaybe my targeting of parameter discarding is too strong, but it _really_ seems like there should be some way to configure TypeScript to block the [assertion](https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Basic%20Types.md#type-assertions) of a `C2` instance to a `C1` interface without requiring me to just write better code like:\n\n``` ts\nclass betterC1 { one(hi: string, ...restHi: string[]) { } }\n```\n","author":{"url":"https://github.com/SlurpTheo","@type":"Person","name":"SlurpTheo"},"datePublished":"2016-06-24T22:01:49Z","url":"https://github.com/microsoft/TypeScript/issues/9352"}

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:ae735059-4212-f1ad-7024-7178c4ba706b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE9CC:272DC0:55A710:6ECB4A:6B00DAB8
html-safe-nonced75ad14eff5ec981d4346d1558184b49c119b0bb8a6f5353230c14d856c71fb7
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOUNDOjI3MkRDMDo1NUE3MTA6NkVDQjRBOjZCMDBEQUI4IiwidmlzaXRvcl9pZCI6Ijg0NjAxNjUzMDk0NTI1NzMzNjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmace701d6c44f34f605c12588604abbf6f0d431ecaea2c4025c937490c674b05a7a
hovercard-subject-tagissue:162238912
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/9352/issue_layout
twitter:imagehttps://opengraph.githubassets.com/e1b74c297e6a1943f1a5900d0f1a007950248ef09740ac34547142453822ef8a/microsoft/TypeScript/issues/9352
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/e1b74c297e6a1943f1a5900d0f1a007950248ef09740ac34547142453822ef8a/microsoft/TypeScript/issues/9352
og:image:altAfter reading the Comparing two functions section of the handbook I got myself pretty confused and concerned. I have an example below that I think (taken to the prepare-for-duck-typing-extreme) mea...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameSlurpTheo
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-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/9352#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F9352
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%2F9352
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/9352
Reloadhttps://github.com/microsoft/TypeScript/issues/9352
Reloadhttps://github.com/microsoft/TypeScript/issues/9352
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/9352
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/9352
'Discarding Parameters' plus 'Duck Typing' makes every parameter optional?https://github.com/microsoft/TypeScript/issues/9352#top
Design LimitationConstraints of the existing architecture prevent this from being fixedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Design%20Limitation%22
https://github.com/SlurpTheo
SlurpTheohttps://github.com/SlurpTheo
on Jun 24, 2016https://github.com/microsoft/TypeScript/issues/9352#issue-162238912
Comparing two functionshttps://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Type%20Compatibility.md#comparing-two-functions
assertionhttps://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Basic%20Types.md#type-assertions
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Jun 24, 2016https://github.com/microsoft/TypeScript/issues/9352#issuecomment-228475845
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Design LimitationConstraints of the existing architecture prevent this from being fixedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Design%20Limitation%22
on Jun 24, 2016https://github.com/microsoft/TypeScript/issues/9352#event-703770136
https://github.com/SlurpTheo
SlurpTheohttps://github.com/SlurpTheo
on Jun 27, 2016https://github.com/microsoft/TypeScript/issues/9352#issuecomment-228747481
Ryan Cavanaugh (@RyanCavanaugh)https://github.com/RyanCavanaugh
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Jun 27, 2016https://github.com/microsoft/TypeScript/issues/9352#issuecomment-228798994
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jun 28, 2016https://github.com/microsoft/TypeScript/issues/9352#event-705952520
https://github.com/SlurpTheo
SlurpTheohttps://github.com/SlurpTheo
on Jun 15, 2017https://github.com/microsoft/TypeScript/issues/9352#issuecomment-308776216
https://github.com/Microsoft/TypeScript/wiki/What%27s-new-in-TypeScript#strict-contravariance-for-callback-parametershttps://github.com/Microsoft/TypeScript/wiki/What%27s-new-in-TypeScript#strict-contravariance-for-callback-parameters
Covariant checking for callback parameters #15104https://github.com/microsoft/TypeScript/pull/15104
Stricter generic signature checks #16368https://github.com/microsoft/TypeScript/pull/16368
Contextual generic function types #16305https://github.com/microsoft/TypeScript/pull/16305
Infer from generic function return types #16072https://github.com/microsoft/TypeScript/pull/16072
Smarter type inference for functional programming (RxJS, Ramda, etc) #15680https://github.com/microsoft/TypeScript/issues/15680
Strict function types #18654 (comment)https://github.com/microsoft/TypeScript/pull/18654#issuecomment-336274851
Strict function variance fixes DefinitelyTyped/DefinitelyTyped#20219 (comment)https://github.com/DefinitelyTyped/DefinitelyTyped/pull/20219#issue-262255340
microsofthttps://github.com/microsoft
on Jun 19, 2018https://github.com/microsoft/TypeScript/issues/9352#event-1689840572
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/9352
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/9352
Design LimitationConstraints of the existing architecture prevent this from being fixedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Design%20Limitation%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.