Title: emitDecoratorMetadata combined with template literals throws exception and exits · Issue #38428 · microsoft/TypeScript · GitHub
Open Graph Title: emitDecoratorMetadata combined with template literals throws exception and exits · Issue #38428 · microsoft/TypeScript
X Title: emitDecoratorMetadata combined with template literals throws exception and exits · Issue #38428 · microsoft/TypeScript
Description: This is an edge case, but my team for various reasons decided to use template literals everywhere instead of strings. In almost all cases this seems to not have any drawbacks, except this case I'm reporting and one other edge case I may ...
Open Graph Description: This is an edge case, but my team for various reasons decided to use template literals everywhere instead of strings. In almost all cases this seems to not have any drawbacks, except this case I'm ...
X Description: This is an edge case, but my team for various reasons decided to use template literals everywhere instead of strings. In almost all cases this seems to not have any drawbacks, except this case I...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/38428
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"emitDecoratorMetadata combined with template literals throws exception and exits","articleBody":"This is an edge case, but my team for various reasons decided to use template literals everywhere instead of strings. In almost all cases this seems to not have any drawbacks, except this case I'm reporting and one other edge case I may report separately. Maybe we shouldn't be using template literals in this spot, but the transpilation should probably not crash regardless. In our scenario `emitDecoratorMetadata` is required (for TypeORM) and that option is required to reproduce the bug.\r\n\r\n**TypeScript Version:** \r\n3.8.3\r\ntypescript@next 4.0.0-dev.20200508\r\n\r\n**Search Terms:**\r\ndecorator\r\nquotes\r\nbacktick\r\n\r\n**Code**\r\n\r\n```ts\r\nimport \"reflect-metadata\";\r\n\r\nconst formatMetadataKey = Symbol(\"format\");\r\n\r\nfunction format(formatString: string) {\r\n return Reflect.metadata(formatMetadataKey, formatString);\r\n}\r\n\r\nfunction getFormat(target: any, propertyKey: string) {\r\n return Reflect.getMetadata(formatMetadataKey, target, propertyKey);\r\n}\r\n\r\n\r\nclass Greeter {\r\n @format(\"Hello, %s\")\r\n greeting: `boss` | `employee` = `employee`; //template literals on this line cause the issue\r\n\r\n constructor(message: 'boss' | 'employee') {\r\n this.greeting = message;\r\n }\r\n greet() {\r\n const formatString = getFormat(this, \"greeting\");\r\n return formatString.replace(\"%s\", this.greeting);\r\n }\r\n}\r\n\r\nconst g = new Greeter('boss')\r\ng.greet()\r\n```\r\n\r\n**Expected behavior:**\r\nCompiles normally.\r\n\r\n**Actual behavior:**\r\nThrows exception: \r\n```\r\n/Users/jcullison/.config/yarn/global/node_modules/typescript/lib/tsc.js:81040\r\n throw e;\r\n ^\r\nError: Debug Failure. Unexpected node.\r\nNode 14 was unexpected.\r\n at serializeTypeNode (/Users/jcullison/.config/yarn/global/node_modules/typescript/lib/tsc.js:64342:45)\r\n at serializeTypeList (/Users/jcullison/.config/yarn/global/node_modules/typescript/lib/tsc.js:64391:44)\r\n at serializeTypeNode (/Users/jcullison/.config/yarn/global/node_modules/typescript/lib/tsc.js:64356:28)\r\n at serializeTypeOfNode (/Users/jcullison/.config/yarn/global/node_modules/typescript/lib/tsc.js:64249:28)\r\n at addOldTypeMetadata (/Users/jcullison/.config/yarn/global/node_modules/typescript/lib/tsc.js:64191:92)\r\n at addTypeMetadata (/Users/jcullison/.config/yarn/global/node_modules/typescript/lib/tsc.js:64185:17)\r\n at transformAllDecoratorsOfDeclaration (/Users/jcullison/.config/yarn/global/node_modules/typescript/lib/tsc.js:64104:13)\r\n at generateClassElementDecorationExpression (/Users/jcullison/.config/yarn/global/node_modules/typescript/lib/tsc.js:64129:40)\r\n at generateClassElementDecorationExpressions (/Users/jcullison/.config/yarn/global/node_modules/typescript/lib/tsc.js:64115:34)\r\n at addClassElementDecorationStatements (/Users/jcullison/.config/yarn/global/node_modules/typescript/lib/tsc.js:64108:44)\r\n```\r\n**Playground Link:** [Provided](https://www.typescriptlang.org/play/?experimentalDecorators=true&emitDecoratorMetadata=true&target=6#code/JYWwDg9gTgLgBAIigUwGYBtkGMYFoTIwCGAJkcQgNwBQ1WEAdgM7yrQjkCyhp5RA0sgCecALxwAykJAAjCOgAUCNlA4wEAShrVUAVwY5gjOCrULT5CTCjAGAcwBccFjfsa4Ab2pw4KGLqgGOAAlNEwcADoCYjJic3YuHliBYQAaEwSYK1c7LWoAX1o9AxgjILtCADFMhWIoCpgnIgYhdLAoCDBkWCFBIScXW1zPb19CAKDQjGwYCIbuGL541UTF4j70uoa2jq6evrzC2ix0IiYmOABxFEJukZ8AAQsYJQAJZHR0CHSAUiZNUZ2G6lexOAAGcnOYLgAB84GDkOAvkJkMhoeIAOSIsDI1EY7Q+ejMay6HDQBQEc5ECpODGQpgY2FwLFIiAo5AY9xeHw+GAAC2ATDmwKGYjglKY1OQNB8hR8QNRLy5o0JjBYGRWWWsovEDWqmtqAqY6QQCsIQ00Mp5fgmGrU2SGERQOKIWGQSj+CE2RuFiqGeVlBWOavgdjFDGQAHcrsDugo6RBzpzqHZfYQFBogA)\r\n\r\nConsole output:\r\nError: Debug Failure. Unexpected node.\r\nNode NoSubstitutionTemplateLiteral was unexpected.\r\n\r\n**Related Issues:**\r\n(similar idea) https://github.com/microsoft/TypeScript/issues/37276\r\n\r\n**Example cli:***\r\n`tsc --outdir ./build --target ES2019 --experimentalDecorators -emitDecoratorMetadata ./test-param-decorator.ts`","author":{"url":"https://github.com/culli","@type":"Person","name":"culli"},"datePublished":"2020-05-08T20:24:12Z","url":"https://github.com/microsoft/TypeScript/issues/38428"}
| 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:b1b48998-3153-6db5-c8a1-cd3450470230 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9A5A:2564F:EC0C6B:137FF71:6B0101A6 |
| html-safe-nonce | 56b0495aec7475c92d8529c9e7e7119d0c6c48658ff7288dcaea1acbbfc39a2e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QTVBOjI1NjRGOkVDMEM2QjoxMzdGRjcxOjZCMDEwMUE2IiwidmlzaXRvcl9pZCI6Ijc5MjMxMjMzMDc0MzAzNDcxNzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | be07e458177282a9edc466bc801894e80bc29ee6d52d4718f963252cabec9058 |
| hovercard-subject-tag | issue:614967373 |
| 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/38428/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e4e041a99b0f2f19069e7adb4e0c8e8537d8bc93ad29e79ec92201b4c5a760b5/microsoft/TypeScript/issues/38428 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e4e041a99b0f2f19069e7adb4e0c8e8537d8bc93ad29e79ec92201b4c5a760b5/microsoft/TypeScript/issues/38428 |
| og:image:alt | This is an edge case, but my team for various reasons decided to use template literals everywhere instead of strings. In almost all cases this seems to not have any drawbacks, except this case I'm ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | culli |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width