Title: JSON.stringify() type does not include `this` type for replacer function · Issue #28632 · microsoft/TypeScript · GitHub
Open Graph Title: JSON.stringify() type does not include `this` type for replacer function · Issue #28632 · microsoft/TypeScript
X Title: JSON.stringify() type does not include `this` type for replacer function · Issue #28632 · microsoft/TypeScript
Description: The lib.d.ts does not contain a this type for the replacer callback, although this is explicitly set by the runtime to the value of holder according to "https://www.ecma-international.org/ecma-262/5.1/#sec-15.12.3". I would suggest an an...
Open Graph Description: The lib.d.ts does not contain a this type for the replacer callback, although this is explicitly set by the runtime to the value of holder according to "https://www.ecma-international.org/ecma-262/...
X Description: The lib.d.ts does not contain a this type for the replacer callback, although this is explicitly set by the runtime to the value of holder according to "https://www.ecma-international.org/ecma...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/28632
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"JSON.stringify() type does not include `this` type for replacer function","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\nThe lib.d.ts does not contain a `this` type for the replacer callback, although this is explicitly set by the runtime to the value of holder according to \"https://www.ecma-international.org/ecma-262/5.1/#sec-15.12.3\". I would suggest an any type for this.\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 3.2.0-dev.20181117\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** JSON serialize replacer this\r\n\r\n**Code**\r\n\r\n```ts\r\nfunction serialize(key, value) {\r\n return value;\r\n}\r\n\r\nfunction test() {\r\n JSON.stringify({foo: \"bar\"}, function (key) {\r\n // !!! this should be legal !!!\r\n return serialize(key, this[key]);\r\n });\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nCompilation without error with \"noImplicitThis\" compilerOption being activated.\r\n\r\n**Actual behavior:**\r\ntsc reports an error saying \"'this' implicitly has type 'any' because it does not have a type annotation.\" when noImplicitThis is activated.\r\n\r\n**Playground Link:**\r\nhttps://www.typescriptlang.org/play/index.html#src=function%20serialize(key%2C%20value)%20%7B%0D%0A%20%20%20%20return%20value%3B%0D%0A%7D%0D%0A%0D%0Afunction%20test()%20%7B%0D%0A%20%20%20%20JSON.stringify(%7Bfoo%3A%20%22bar%22%7D%2C%20function%20(key)%20%7B%0D%0A%20%20%20%20%20%20%20%20%2F%2F%20!!!%20this%20should%20be%20legal%20!!!%0D%0A%20%20%20%20%20%20%20%20return%20serialize(key%2C%20this%5Bkey%5D)%3B%0D%0A%20%20%20%20%7D)%3B%0D%0A%7D\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\nnone found","author":{"url":"https://github.com/Haringat","@type":"Person","name":"Haringat"},"datePublished":"2018-11-21T10:40:30Z","url":"https://github.com/microsoft/TypeScript/issues/28632"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d7002a88-7050-8339-edb2-6617d5f8e6a8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8018:A99C2:918C9F:BD4266:6B00DD2B |
| html-safe-nonce | 26061497d55bd14dd542a7bef0397b73a6a9bc3bbc7ce9ca16e271f379e63062 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDE4OkE5OUMyOjkxOEM5RjpCRDQyNjY6NkIwMEREMkIiLCJ2aXNpdG9yX2lkIjoiMjc0MjY3NDQyMzc2NDAxNjQyNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ae33e18be4a6f4d19f6758ad6c58da0f931f1fb0b7eb0f3e78d5212c067fcd24 |
| hovercard-subject-tag | issue:383056712 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/28632/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d62659c0f02d70656b754f664430618c4672b1c6ec1e7e1858e0fe1a7a7b7a40/microsoft/TypeScript/issues/28632 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d62659c0f02d70656b754f664430618c4672b1c6ec1e7e1858e0fe1a7a7b7a40/microsoft/TypeScript/issues/28632 |
| og:image:alt | The lib.d.ts does not contain a this type for the replacer callback, although this is explicitly set by the runtime to the value of holder according to "https://www.ecma-international.org/ecma-262/... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Haringat |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width