Title: Design:type metadata for cyclic dependencies throw at runtime · Issue #27519 · microsoft/TypeScript · GitHub
Open Graph Title: Design:type metadata for cyclic dependencies throw at runtime · Issue #27519 · microsoft/TypeScript
X Title: Design:type metadata for cyclic dependencies throw at runtime · Issue #27519 · microsoft/TypeScript
Description: TypeScript Version: 3.2.0-dev.20181003 Search Terms: design cyclic Code index.ts import 'reflect-metadata'; function property() { return (target: Object, key: string) => { const t = Reflect.getMetadata('design:type', target, key); consol...
Open Graph Description: TypeScript Version: 3.2.0-dev.20181003 Search Terms: design cyclic Code index.ts import 'reflect-metadata'; function property() { return (target: Object, key: string) => { const t = Reflect.getMeta...
X Description: TypeScript Version: 3.2.0-dev.20181003 Search Terms: design cyclic Code index.ts import 'reflect-metadata'; function property() { return (target: Object, key: string) => { const t = Refl...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/27519
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Design:type metadata for cyclic dependencies throw at runtime","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\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.20181003\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** design cyclic\r\n\r\n**Code**\r\n\r\n_index.ts_\r\n\r\n```ts\r\nimport 'reflect-metadata';\r\n\r\nfunction property() {\r\n return (target: Object, key: string) => {\r\n const t = Reflect.getMetadata('design:type', target, key);\r\n console.log('property %s#%s of type', target.constructor.name, key, t.name);\r\n }\r\n}\r\n\r\nclass Product {\r\n // belongs to a category\r\n @property()\r\n category: Category;\r\n}\r\n\r\nclass Category {\r\n // has many products\r\n @property()\r\n products: Product[];\r\n}\r\n```\r\n\r\n_tsconfig.json_\r\n```json\r\n{\r\n \"$schema\": \"http://json.schemastore.org/tsconfig\",\r\n \"compilerOptions\": {\r\n \"emitDecoratorMetadata\": true,\r\n \"experimentalDecorators\": true,\r\n\r\n \"lib\": [\"es2018\", \"dom\"],\r\n \"module\": \"commonjs\",\r\n \"moduleResolution\": \"node\",\r\n \"target\": \"es2017\"\r\n },\r\n \"include\": [\r\n \"index.ts\"\r\n ]\r\n}\r\n```\r\n\r\n_package.json_\r\n```json\r\n{\r\n \"dependencies\": {\r\n \"reflect-metadata\": \"^0.1.12\",\r\n \"typescript\": \"^3.2.0-dev.20181003\"\r\n }\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nIdeally, the code compiles and `node index.js` produces the following console output:\r\n\r\n```\r\nproperty Product#category of type Category\r\nproperty Category#products of type Array\r\n```\r\n\r\nIf this is not possible, then the compiler should detect cyclic dependencies and fail the compilation with a helpful error.\r\n\r\n**Actual behavior:**\r\n\r\nThe code compiles. When the compiled code is executed, it fails at runtime.\r\n\r\n```\r\nindex.js:23\r\n __metadata(\"design:type\", Category)\r\n ^\r\n\r\nReferenceError: Category is not defined\r\n at Object.\u003canonymous> (index.js:23:31)\r\n at Module._compile (internal/modules/cjs/loader.js:689:30)\r\n (...)\r\n```\r\n\r\nHere is the relevant snippet from the transpiled output:\r\n\r\n```js\r\nclass Product {\r\n}\r\n__decorate([\r\n property(),\r\n __metadata(\"design:type\", Category)\r\n], Product.prototype, \"category\", void 0);\r\n\r\nclass Category {\r\n}\r\n__decorate([\r\n property(),\r\n __metadata(\"design:type\", Array)\r\n], Category.prototype, \"products\", void 0);\r\n```\r\n\r\n**Playground Link:** \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior -->\r\n\r\nPlayground does not support `emitDecoratorMetadata` and `experimentalDecorators` options ☹️ \r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\n\r\nNone found.","author":{"url":"https://github.com/bajtos","@type":"Person","name":"bajtos"},"datePublished":"2018-10-03T07:05:44Z","url":"https://github.com/microsoft/TypeScript/issues/27519"}
| 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:bd4f9e63-966b-d4ec-2f03-17c05aa2c08f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A696:14F601:2E5DF8D:3AD3B4F:6B01A46D |
| html-safe-nonce | 49bf3705b76aa62896f9b26d6a460ca00eb6cc96e877b8a06b739d5505ada290 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNjk2OjE0RjYwMToyRTVERjhEOjNBRDNCNEY6NkIwMUE0NkQiLCJ2aXNpdG9yX2lkIjoiNjM0MzIwMzEyNDk4NzE0MzI3NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 09398585658fd19a7d45e54e401171f15d063a2a7d2198cf24db2ca4bcc66c39 |
| hovercard-subject-tag | issue:366201541 |
| 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/27519/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2d4d5e7998f14e1d06d59b44d6d7dfa097aa3e94df46cf34bab95c758d0c1198/microsoft/TypeScript/issues/27519 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2d4d5e7998f14e1d06d59b44d6d7dfa097aa3e94df46cf34bab95c758d0c1198/microsoft/TypeScript/issues/27519 |
| og:image:alt | TypeScript Version: 3.2.0-dev.20181003 Search Terms: design cyclic Code index.ts import 'reflect-metadata'; function property() { return (target: Object, key: string) => { const t = Reflect.getMeta... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bajtos |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width