René's URL Explorer Experiment


Title: Bug Report + Proposal: Object.assign() · Issue #31982 · microsoft/TypeScript · GitHub

Open Graph Title: Bug Report + Proposal: Object.assign() · Issue #31982 · microsoft/TypeScript

X Title: Bug Report + Proposal: Object.assign() · Issue #31982 · microsoft/TypeScript

Description: TypeScript Version: 3.4.0-dev.201xxxxx Search Terms: Object.assign return type Code let test1: string = Object.assign({ a: 1 }, { a: "one" }).a // $ExpectError let test2: number = Object.assign({ a: 1 }, { a: "one" }).a // No error // $E...

Open Graph Description: TypeScript Version: 3.4.0-dev.201xxxxx Search Terms: Object.assign return type Code let test1: string = Object.assign({ a: 1 }, { a: "one" }).a // $ExpectError let test2: number = Object.assign({ a...

X Description: TypeScript Version: 3.4.0-dev.201xxxxx Search Terms: Object.assign return type Code let test1: string = Object.assign({ a: 1 }, { a: "one" }).a // $ExpectError let test2: number = Object....

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bug Report + Proposal: Object.assign()","articleBody":"\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:**  3.4.0-dev.201xxxxx\r\n\r\n**Search Terms:** Object.assign return type\r\n\r\n**Code**\r\n\r\n1.\r\n\r\n```ts\r\nlet test1: string = Object.assign({ a: 1 }, { a: \"one\" }).a\r\n// $ExpectError\r\nlet test2: number = Object.assign({ a: 1 }, { a: \"one\" }).a // No error\r\n```\r\n\r\n2.\r\n```ts\r\n// $ExpectError\r\nObject.assign({ a: 1, b: 2 }, \"hi\").toLowerCase() // No error\r\n```\r\n\r\n3.\r\n\r\n```ts\r\n// $ExpectError\r\nObject.assign({ a: 1, b: 2 }, \"hi\").length // No error\r\n```\r\n\r\n**Expected behavior:**\r\n\r\n1.\r\n\r\n> Type 'string' is not assignable to type 'number'\r\n\r\n2.\r\n\r\n> Property 'toLowerCase' does not exist on type ...\r\n\r\n3. \r\n\r\n> Property 'length' does not exist on type ...\r\n\r\n**Actual behavior:**\r\n\r\nNo errors raised.\r\n\r\n**Playground Link:**  [Link](https://www.typescriptlang.org/play/#src=%2F%2F%20Pass%0D%0Alet%20test1%3A%20string%20%3D%20Object.assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20%22one%22%20%7D).a%0D%0A%0D%0A%2F%2F%20Failure%0D%0A%2F%2F%20Should%20raise%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'string'%20is%20not%20assignable%20to%20type%20'number'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test2%3A%20number%20%3D%20Object.assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20%22one%22%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test3%3A%20string%20%3D%20Object.assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20(0%20as%20any)%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test4%3A%20number%20%3D%20Object.assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20undefined%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass...%20sort%20of%0D%0A%2F%2F%20Should%20raise%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'number'%20is%20not%20assignable%20to%20type%20'string'%0D%0A%2F%2F%20Note%3A%20The%20the%20error%20message%20is%20incorrect%20and%20demonstrative%20of%20the%20issue%20at%20hand.%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test5%3A%20string%20%3D%20Object.assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20%7B%7D%20%7D).a%20%0D%0A%0D%0A%2F%2F%20Failure%0D%0A%2F%2F%20Should%20raise%3A%0D%0A%2F%2F%20%20%20%20%20Property%20'toLowerCase'%20does%20not%20exist%20on%20type%20...%0D%0A%2F%2F%20%24ExpectError%0D%0AObject.assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22).toLowerCase()%20%2F%2F%20test6%0D%0A%0D%0A%2F%2F%20Pass%0D%0AObject.assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22)%5B%22a%22%5D%20%2F%2F%20test7%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test8%3A%20string%20%3D%20Object.assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22)%5B0%5D%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'string'%20is%20not%20assignable%20to%20type%20'number'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test9%3A%20number%20%3D%20Object.assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22)%5B0%5D%0D%0A%0D%0A%2F%2F%20Failure%0D%0A%2F%2F%20Should%20raise%3A%0D%0A%2F%2F%20%20%20%20%20Property%20'length'%20does%20not%20exist%20on%20type%20...%0D%0A%2F%2F%20%24ExpectError%0D%0AObject.assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22).length%20%2F%2F%20test10%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test11%3A%20number%20%3D%20Object.assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%5B1%2C%202%2C%203%5D)%5B0%5D%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'number'%20is%20not%20assignable%20to%20type%20'string'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test12%3A%20string%20%3D%20Object.assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%5B1%2C%202%2C%203%5D)%5B0%5D%0D%0A)\r\n\r\n**Related Issues:** \r\n\r\n* https://github.com/microsoft/TypeScript/pull/30481\r\n* https://github.com/microsoft/TypeScript/issues/29348\r\n\r\n# Proposal\r\n\r\n```ts\r\ntype IndexerReturnType\u003cT extends ArrayLike\u003cany>> = T extends ArrayLike\u003cinfer V> ? V : any;\r\n\r\ntype ArrayLikeIndexer\u003cT> = T extends ArrayLike\u003cany> ? { [k: number]: IndexerReturnType\u003cT> } : never \r\n\r\ntype PickDefined\u003cT> = {\r\n    [P in keyof T]: T[P] extends undefined ? never : T[P]\r\n};\r\n\r\ntype Assign\u003cA, B> = A extends object ? (\r\n    B extends object ?\r\n        Pick\u003cA, Exclude\u003ckeyof A, keyof B>> & PickDefined\u003cB> :\r\n        A & ArrayLikeIndexer\u003cB>\r\n) : (A & B)\r\n\r\ndeclare function assign\u003cA, B>(a: A, b: B): Assign\u003cA, B>\r\n```\r\n\r\n**Note 1**: _`PickDefined\u003cT>` is necessary with `strictNullChecks` enabled._\r\n**Note 2**: _In the definition of `Assign\u003cA, B>` I would have expected the usage of `keyof B` to need to be replaced with `keyof PickDefined\u003cB>`. It seems, that's _presently_ not the case - so I've opted to omit it and avoid any potential slow-down. Nonetheless, I must admit that I'm hazy as to why this is permissible._\r\n\r\nObviously to keep things brief I've just covered the single `source` use-case rather than providing overloads with several source. The definition is nonetheless chainable i.e. `Assign\u003cA, Assign\u003cB, C>>` etc. \r\n\r\n**Playground Link:** [Link](https://www.typescriptlang.org/play/#src=%2F%2F%20*****%20Proposed%20Definition%20*****%0D%0A%0D%0Atype%20IndexerReturnType%3CT%20extends%20ArrayLike%3Cany%3E%3E%20%3D%20T%20extends%20ArrayLike%3Cinfer%20V%3E%20%3F%20V%20%3A%20any%3B%0D%0A%0D%0Atype%20ArrayLikeIndexer%3CT%3E%20%3D%20T%20extends%20ArrayLike%3Cany%3E%20%3F%20%7B%20%5Bk%3A%20number%5D%3A%20IndexerReturnType%3CT%3E%20%7D%20%3A%20never%20%0D%0A%0D%0Atype%20PickDefined%3CT%3E%20%3D%20%7B%0D%0A%20%20%20%20%5BP%20in%20keyof%20T%5D%3A%20T%5BP%5D%20extends%20undefined%20%3F%20never%20%3A%20T%5BP%5D%0D%0A%7D%3B%0D%0A%0D%0Atype%20Assign%3CA%2C%20B%3E%20%3D%20A%20extends%20object%20%3F%20(%0D%0A%20%20%20%20B%20extends%20object%20%3F%20Pick%3CA%2C%20Exclude%3Ckeyof%20A%2C%20keyof%20B%3E%3E%20%26%20PickDefined%3CB%3E%20%3A%20A%20%26%20ArrayLikeIndexer%3CB%3E%0D%0A)%20%3A%20(A%20%26%20B)%0D%0A%0D%0A%2F%2F%20Note%3A%20In%20the%20above%20I%20would%20have%20expected%20%60keyof%20B%60%20to%20need%20to%20be%20%60keyof%20PickDefined%3CB%3E%60%2C%0D%0A%2F%2F%20however%20that's%20*presently*%20not%20the%20case%20-%20so%20no%20point%20slowing%20TypeScript%20down.%0D%0A%0D%0Adeclare%20function%20assign%3CA%2C%20B%3E(a%3A%20A%2C%20b%3A%20B)%3A%20Assign%3CA%2C%20B%3E%0D%0A%0D%0A%2F%2F%20*****%20Tests%20*****%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test1%3A%20string%20%3D%20assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20%22one%22%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'string'%20is%20not%20assignable%20to%20type%20'number'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test2%3A%20number%20%3D%20assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20%22one%22%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test3%3A%20string%20%3D%20assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20(0%20as%20any)%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test4%3A%20number%20%3D%20assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20undefined%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'number'%20is%20not%20assignable%20to%20type%20'string'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test5%3A%20string%20%3D%20assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20%7B%7D%20%7D).a%20%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Property%20'toLowerCase'%20does%20not%20exist%20on%20type%20...%0D%0A%2F%2F%20%24ExpectError%0D%0Aassign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22).toLowerCase()%20%2F%2F%20test6%0D%0A%0D%0A%2F%2F%20Pass%0D%0Aassign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22)%5B%22a%22%5D%20%2F%2F%20test7%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test8%3A%20string%20%3D%20assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22)%5B0%5D%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'string'%20is%20not%20assignable%20to%20type%20'number'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test9%3A%20number%20%3D%20assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22)%5B0%5D%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Property%20'length'%20does%20not%20exist%20on%20type%20...%0D%0A%2F%2F%20%24ExpectError%0D%0Aassign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22).length%20%2F%2F%20test10%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test11%3A%20number%20%3D%20assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%5B1%2C%202%2C%203%5D)%5B0%5D%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'number'%20is%20not%20assignable%20to%20type%20'string'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test12%3A%20string%20%3D%20assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%5B1%2C%202%2C%203%5D)%5B0%5D%0D%0A) (For posterity please enable `strictNullChecks`)","author":{"url":"https://github.com/Benjamin-Dobell","@type":"Person","name":"Benjamin-Dobell"},"datePublished":"2019-06-19T15:25:16Z","url":"https://github.com/microsoft/TypeScript/issues/31982"}

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:9466b3d0-f446-a692-5c2c-b4e76bbc3b4a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE2F8:27D3AD:3090D7C:3DAD80D:6B01C74A
html-safe-nonceb4c63b7e335a6c67f8975248380c3fe8c27067361996845c353e4de4fb9e5924
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMkY4OjI3RDNBRDozMDkwRDdDOjNEQUQ4MEQ6NkIwMUM3NEEiLCJ2aXNpdG9yX2lkIjoiNTY2MTkwNDQyMDAxMTYyNDI2NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac8e02427e55cacd09a9f465820d2d70777185e0c6d2bf8d07517dfbe04062af39
hovercard-subject-tagissue:458079416
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/31982/issue_layout
twitter:imagehttps://opengraph.githubassets.com/83524fe10929b6bf1d8ccab4d6c831a2e5d8c9fd57c46e337d0aa2b9c359578c/microsoft/TypeScript/issues/31982
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/83524fe10929b6bf1d8ccab4d6c831a2e5d8c9fd57c46e337d0aa2b9c359578c/microsoft/TypeScript/issues/31982
og:image:altTypeScript Version: 3.4.0-dev.201xxxxx Search Terms: Object.assign return type Code let test1: string = Object.assign({ a: 1 }, { a: "one" }).a // $ExpectError let test2: number = Object.assign({ a...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameBenjamin-Dobell
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
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
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/31982#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F31982
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%2F31982
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/31982
Reloadhttps://github.com/microsoft/TypeScript/issues/31982
Reloadhttps://github.com/microsoft/TypeScript/issues/31982
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests312 (312)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/31982
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/31982
Bug Report + Proposal: Object.assign()https://github.com/microsoft/TypeScript/issues/31982#top
Working as IntendedThe behavior described is the intended behavior; this is not a bughttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Working%20as%20Intended%22
https://github.com/Benjamin-Dobell
Benjamin Dobell (Benjamin-Dobell)https://github.com/Benjamin-Dobell
on Jun 19, 2019https://github.com/microsoft/TypeScript/issues/31982#issue-458079416
Linkhttps://www.typescriptlang.org/play/#src=%2F%2F%20Pass%0D%0Alet%20test1%3A%20string%20%3D%20Object.assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20%22one%22%20%7D).a%0D%0A%0D%0A%2F%2F%20Failure%0D%0A%2F%2F%20Should%20raise%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'string'%20is%20not%20assignable%20to%20type%20'number'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test2%3A%20number%20%3D%20Object.assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20%22one%22%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test3%3A%20string%20%3D%20Object.assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20(0%20as%20any)%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test4%3A%20number%20%3D%20Object.assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20undefined%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass...%20sort%20of%0D%0A%2F%2F%20Should%20raise%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'number'%20is%20not%20assignable%20to%20type%20'string'%0D%0A%2F%2F%20Note%3A%20The%20the%20error%20message%20is%20incorrect%20and%20demonstrative%20of%20the%20issue%20at%20hand.%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test5%3A%20string%20%3D%20Object.assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20%7B%7D%20%7D).a%20%0D%0A%0D%0A%2F%2F%20Failure%0D%0A%2F%2F%20Should%20raise%3A%0D%0A%2F%2F%20%20%20%20%20Property%20'toLowerCase'%20does%20not%20exist%20on%20type%20...%0D%0A%2F%2F%20%24ExpectError%0D%0AObject.assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22).toLowerCase()%20%2F%2F%20test6%0D%0A%0D%0A%2F%2F%20Pass%0D%0AObject.assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22)%5B%22a%22%5D%20%2F%2F%20test7%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test8%3A%20string%20%3D%20Object.assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22)%5B0%5D%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'string'%20is%20not%20assignable%20to%20type%20'number'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test9%3A%20number%20%3D%20Object.assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22)%5B0%5D%0D%0A%0D%0A%2F%2F%20Failure%0D%0A%2F%2F%20Should%20raise%3A%0D%0A%2F%2F%20%20%20%20%20Property%20'length'%20does%20not%20exist%20on%20type%20...%0D%0A%2F%2F%20%24ExpectError%0D%0AObject.assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22).length%20%2F%2F%20test10%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test11%3A%20number%20%3D%20Object.assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%5B1%2C%202%2C%203%5D)%5B0%5D%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'number'%20is%20not%20assignable%20to%20type%20'string'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test12%3A%20string%20%3D%20Object.assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%5B1%2C%202%2C%203%5D)%5B0%5D%0D%0A
Generic type-safe implementation for Object.assign #30481https://github.com/microsoft/TypeScript/pull/30481
Object.assign({}) seems to always return a type any #29348https://github.com/microsoft/TypeScript/issues/29348
Linkhttps://www.typescriptlang.org/play/#src=%2F%2F%20*****%20Proposed%20Definition%20*****%0D%0A%0D%0Atype%20IndexerReturnType%3CT%20extends%20ArrayLike%3Cany%3E%3E%20%3D%20T%20extends%20ArrayLike%3Cinfer%20V%3E%20%3F%20V%20%3A%20any%3B%0D%0A%0D%0Atype%20ArrayLikeIndexer%3CT%3E%20%3D%20T%20extends%20ArrayLike%3Cany%3E%20%3F%20%7B%20%5Bk%3A%20number%5D%3A%20IndexerReturnType%3CT%3E%20%7D%20%3A%20never%20%0D%0A%0D%0Atype%20PickDefined%3CT%3E%20%3D%20%7B%0D%0A%20%20%20%20%5BP%20in%20keyof%20T%5D%3A%20T%5BP%5D%20extends%20undefined%20%3F%20never%20%3A%20T%5BP%5D%0D%0A%7D%3B%0D%0A%0D%0Atype%20Assign%3CA%2C%20B%3E%20%3D%20A%20extends%20object%20%3F%20(%0D%0A%20%20%20%20B%20extends%20object%20%3F%20Pick%3CA%2C%20Exclude%3Ckeyof%20A%2C%20keyof%20B%3E%3E%20%26%20PickDefined%3CB%3E%20%3A%20A%20%26%20ArrayLikeIndexer%3CB%3E%0D%0A)%20%3A%20(A%20%26%20B)%0D%0A%0D%0A%2F%2F%20Note%3A%20In%20the%20above%20I%20would%20have%20expected%20%60keyof%20B%60%20to%20need%20to%20be%20%60keyof%20PickDefined%3CB%3E%60%2C%0D%0A%2F%2F%20however%20that's%20*presently*%20not%20the%20case%20-%20so%20no%20point%20slowing%20TypeScript%20down.%0D%0A%0D%0Adeclare%20function%20assign%3CA%2C%20B%3E(a%3A%20A%2C%20b%3A%20B)%3A%20Assign%3CA%2C%20B%3E%0D%0A%0D%0A%2F%2F%20*****%20Tests%20*****%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test1%3A%20string%20%3D%20assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20%22one%22%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'string'%20is%20not%20assignable%20to%20type%20'number'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test2%3A%20number%20%3D%20assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20%22one%22%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test3%3A%20string%20%3D%20assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20(0%20as%20any)%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test4%3A%20number%20%3D%20assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20undefined%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'number'%20is%20not%20assignable%20to%20type%20'string'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test5%3A%20string%20%3D%20assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20%7B%7D%20%7D).a%20%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Property%20'toLowerCase'%20does%20not%20exist%20on%20type%20...%0D%0A%2F%2F%20%24ExpectError%0D%0Aassign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22).toLowerCase()%20%2F%2F%20test6%0D%0A%0D%0A%2F%2F%20Pass%0D%0Aassign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22)%5B%22a%22%5D%20%2F%2F%20test7%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test8%3A%20string%20%3D%20assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22)%5B0%5D%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'string'%20is%20not%20assignable%20to%20type%20'number'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test9%3A%20number%20%3D%20assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22)%5B0%5D%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Property%20'length'%20does%20not%20exist%20on%20type%20...%0D%0A%2F%2F%20%24ExpectError%0D%0Aassign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22).length%20%2F%2F%20test10%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test11%3A%20number%20%3D%20assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%5B1%2C%202%2C%203%5D)%5B0%5D%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'number'%20is%20not%20assignable%20to%20type%20'string'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test12%3A%20string%20%3D%20assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%5B1%2C%202%2C%203%5D)%5B0%5D%0D%0A
https://github.com/jcalz
Joe Calzaretta (jcalz)https://github.com/jcalz
on Jun 19, 2019https://github.com/microsoft/TypeScript/issues/31982#issuecomment-503631970
commenthttps://github.com/microsoft/TypeScript/pull/28553#issuecomment-440004598
#28553https://github.com/microsoft/TypeScript/pull/28553
possible implementationhttps://github.com/Microsoft/TypeScript/pull/21316#issuecomment-359574388
#21316https://github.com/microsoft/TypeScript/pull/21316
Link to codehttps://typescript-play.js.org/#code/C4TwDgpgBAkgdgEwgDwgJwEoWAVzXAFXAgB4CoVgJEBnKAQTTQEMQAZASwGtTm4QAfAKgBeKOUrUEdRi3bdSHOADN0UAGoCAUFCgB+DTqgAuKHxABuLVtCQGTVpx7wkqNGWFiJyKrXtynXn5tXQMAbygAbS5TOBwAWwAjdABdUxcUdCxcfCJIDygAXyNYiAA3dCsbYigABQ4AYy4AEQhlJQgEArEIyNqoJSgeEAB7ZXE08T6Uih8pOhxENo6EfSg4crVTAmmiqttoehoaDgBzOBJ6ABooACFPBlnfaSgRxIArCAbgIwMACluT3mrw+Xx+ugha3qTUuNwAosgGgAbHBIEjDMYMG4Y8b3YQAMjqjRayw2XXuRkhpnoUEJskcCgybhI9wAlCUoH8aYTbqyqspFt8OCM4GZjmcLtc7gI-sxqTdEqZedTxedYdKoGFKVA0Ng8KKAPKg74AOmYqrgsoVrLFZn4VmKWmR5pkmqMDT0pkSIxGSIgfCsugaIpowDQOG+IzQfzAOESSMaZlMobQSlONrCxV0NFY9D+Ge1wbgNF9EBNSJGpz+wAAFhwaGa+UZisVncc7kC-DStUGQ2GI8Ao7Lk2G0zdY-HE4qoCm0wXITQcJBo8wm7oW1oBXAhSKoDX4vFhwx5zq9fgxSdzn8ItOAIwAJgAzDcGqYACwAVgAbEUbquHU6fZQIkojrBAADudx-AARMw0E3NBiTQU2gHFsAp6Lki6FiPuh6JE2uqYcAJqJBYUAAPTkesCTJGgZjocG8RgBwfpQMAHDxBACo4MAxioSWfrlpW1bEJihE4FhJF8hRVHQbOcCnNB1jiZJDRkZRwE+n6fBQAAPlAixIO0ZL0VAjHMax7GcdxvH8aWQlVgcYkQERJoNNJGnQXESToEpWgqcROYgPQ6lUVuO6iswDEjExLHQFZXHATxfFFgJZYVo5onjAFJpBfQHmyYZpKdNBQA
https://github.com/Benjamin-Dobell
Benjamin Dobell (Benjamin-Dobell)https://github.com/Benjamin-Dobell
on Jun 19, 2019https://github.com/microsoft/TypeScript/issues/31982#issuecomment-503652660
Joe Calzaretta (@jcalz)https://github.com/jcalz
chartisthttps://github.com/gionkunz/chartist-js/blob/develop/src/scripts/core.js#L61
#12936https://github.com/microsoft/TypeScript/issues/12936
https://github.com/Benjamin-Dobell
Benjamin Dobell (Benjamin-Dobell)https://github.com/Benjamin-Dobell
on Jun 19, 2019https://github.com/microsoft/TypeScript/issues/31982#issuecomment-503669295
Anders Hejlsberg (@ahejlsberg)https://github.com/ahejlsberg
run against my test suitehttps://www.typescriptlang.org/play/#src=type%20Diff%3CT%2C%20U%3E%20%3D%20T%20extends%20U%20%3F%20never%20%3A%20T%3B%20%0D%0A%0D%0A%2F%2F%20Names%20of%20properties%20in%20T%20with%20types%20that%20include%20undefined%0D%0Atype%20OptionalPropertyNames%3CT%3E%20%3D%0D%0A%20%20%20%20%7B%20%5BK%20in%20keyof%20T%5D%3A%20undefined%20extends%20T%5BK%5D%20%3F%20K%20%3A%20never%20%7D%5Bkeyof%20T%5D%3B%0D%0A%0D%0A%2F%2F%20Common%20properties%20from%20L%20and%20R%20with%20undefined%20in%20R%5BK%5D%20replaced%20by%20type%20in%20L%5BK%5D%0D%0Atype%20SpreadProperties%3CL%2C%20R%2C%20K%20extends%20keyof%20L%20%26%20keyof%20R%3E%20%3D%0D%0A%20%20%20%20%7B%20%5BP%20in%20K%5D%3A%20L%5BP%5D%20%7C%20Diff%3CR%5BP%5D%2C%20undefined%3E%20%7D%3B%0D%0A%0D%0A%2F%2F%20Type%20of%20%7B%20...L%2C%20...R%20%7D%0D%0Atype%20Spread%3CL%2C%20R%3E%20%3D%0D%0A%20%20%20%20%2F%2F%20Properties%20in%20L%20that%20don't%20exist%20in%20R%0D%0A%20%20%20%20%26%20Pick%3CL%2C%20Diff%3Ckeyof%20L%2C%20keyof%20R%3E%3E%0D%0A%20%20%20%20%2F%2F%20Properties%20in%20R%20with%20types%20that%20exclude%20undefined%0D%0A%20%20%20%20%26%20Pick%3CR%2C%20Diff%3Ckeyof%20R%2C%20OptionalPropertyNames%3CR%3E%3E%3E%0D%0A%20%20%20%20%2F%2F%20Properties%20in%20R%2C%20with%20types%20that%20include%20undefined%2C%20that%20don't%20exist%20in%20L%0D%0A%20%20%20%20%26%20Pick%3CR%2C%20Diff%3COptionalPropertyNames%3CR%3E%2C%20keyof%20L%3E%3E%0D%0A%20%20%20%20%2F%2F%20Properties%20in%20R%2C%20with%20types%20that%20include%20undefined%2C%20that%20exist%20in%20L%0D%0A%20%20%20%20%26%20SpreadProperties%3CL%2C%20R%2C%20OptionalPropertyNames%3CR%3E%20%26%20keyof%20L%3E%3B%0D%0A%0D%0Adeclare%20function%20assign%3CA%2C%20B%3E(a%3A%20A%2C%20b%3A%20B)%3A%20Spread%3CA%2C%20B%3E%0D%0A%0D%0A%2F%2F%20*****%20Tests%20*****%0D%0A%0D%0A%2F%2F%20Failure%0D%0Alet%20test1%3A%20string%20%3D%20assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20%22one%22%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'string'%20is%20not%20assignable%20to%20type%20'number'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test2%3A%20number%20%3D%20assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20%22one%22%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test3%3A%20string%20%3D%20assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20(0%20as%20any)%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test4%3A%20number%20%3D%20assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20undefined%20%7D).a%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'number'%20is%20not%20assignable%20to%20type%20'string'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test5%3A%20string%20%3D%20assign(%7B%20a%3A%201%20%7D%2C%20%7B%20a%3A%20%7B%7D%20%7D).a%20%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Property%20'toLowerCase'%20does%20not%20exist%20on%20type%20...%0D%0A%2F%2F%20%24ExpectError%0D%0Aassign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22).toLowerCase()%20%2F%2F%20test6%0D%0A%0D%0A%2F%2F%20Pass%0D%0Aassign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22)%5B%22a%22%5D%20%2F%2F%20test7%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test8%3A%20string%20%3D%20assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22)%5B0%5D%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'string'%20is%20not%20assignable%20to%20type%20'number'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test9%3A%20number%20%3D%20assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22)%5B0%5D%0D%0A%0D%0A%2F%2F%20Failure%0D%0A%2F%2F%20Should%20raise%3A%0D%0A%2F%2F%20%20%20%20%20Property%20'length'%20does%20not%20exist%20on%20type%20...%0D%0A%2F%2F%20%24ExpectError%0D%0Aassign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%22hi%22).length%20%2F%2F%20test10%0D%0A%0D%0A%2F%2F%20Pass%0D%0Alet%20test11%3A%20number%20%3D%20assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%5B1%2C%202%2C%203%5D)%5B0%5D%0D%0A%0D%0A%2F%2F%20Pass%0D%0A%2F%2F%20Correctly%20raises%3A%0D%0A%2F%2F%20%20%20%20%20Type%20'number'%20is%20not%20assignable%20to%20type%20'string'%0D%0A%2F%2F%20%24ExpectError%0D%0Alet%20test12%3A%20string%20%3D%20assign(%7B%20a%3A%201%2C%20b%3A%202%20%7D%2C%20%5B1%2C%202%2C%203%5D)%5B0%5D%0D%0A
Anders Hejlsberg (@ahejlsberg)https://github.com/ahejlsberg
https://github.com/jcalz
Joe Calzaretta (jcalz)https://github.com/jcalz
on Jun 19, 2019https://github.com/microsoft/TypeScript/issues/31982#issuecomment-503679606
missing from undefinedhttps://github.com/Microsoft/TypeScript/issues/13195
https://github.com/Benjamin-Dobell
Benjamin Dobell (Benjamin-Dobell)https://github.com/Benjamin-Dobell
on Jun 19, 2019https://github.com/microsoft/TypeScript/issues/31982#issuecomment-503684570
Anders Hejlsberg (@ahejlsberg)https://github.com/ahejlsberg
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Working as IntendedThe behavior described is the intended behavior; this is not a bughttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Working%20as%20Intended%22
on Jun 26, 2019https://github.com/microsoft/TypeScript/issues/31982#event-2441380103
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Jun 26, 2019https://github.com/microsoft/TypeScript/issues/31982#issuecomment-505936140
https://github.com/Benjamin-Dobell
Benjamin Dobell (Benjamin-Dobell)https://github.com/Benjamin-Dobell
on Jun 26, 2019https://github.com/microsoft/TypeScript/issues/31982#issuecomment-505950473
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Jun 26, 2019https://github.com/microsoft/TypeScript/issues/31982#issuecomment-505955432
https://github.com/typescript-bot
TypeScript Bot (typescript-bot)https://github.com/typescript-bot
on Jun 28, 2019https://github.com/microsoft/TypeScript/issues/31982#issuecomment-506859469
TypeScript Bot (typescript-bot)https://github.com/typescript-bot
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jun 28, 2019https://github.com/microsoft/TypeScript/issues/31982#event-2448290421
microsofthttps://github.com/microsoft
on Oct 21, 2025https://github.com/microsoft/TypeScript/issues/31982#event-20416707057
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/31982
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/31982
Working as IntendedThe behavior described is the intended behavior; this is not a bughttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Working%20as%20Intended%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.