Title: [BUG] Adding a decorator to a class inside a namespace causes assignation to undefined `___exports` · Issue #1634 · TypeScriptToLua/TypeScriptToLua · GitHub
Open Graph Title: [BUG] Adding a decorator to a class inside a namespace causes assignation to undefined `___exports` · Issue #1634 · TypeScriptToLua/TypeScriptToLua
X Title: [BUG] Adding a decorator to a class inside a namespace causes assignation to undefined `___exports` · Issue #1634 · TypeScriptToLua/TypeScriptToLua
Description: Description of the issue In my current project, I created a namespace that is split across different files with the goal of containing declarations of classes that I later declare as global, and make actually global using a decorator, as...
Open Graph Description: Description of the issue In my current project, I created a namespace that is split across different files with the goal of containing declarations of classes that I later declare as global, and ma...
X Description: Description of the issue In my current project, I created a namespace that is split across different files with the goal of containing declarations of classes that I later declare as global, and ma...
Opengraph URL: https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1634
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[BUG] Adding a decorator to a class inside a namespace causes assignation to undefined `___exports`","articleBody":"# Description of the issue\nIn my current project, I created a namespace that is split across different files with the goal of containing declarations of classes that I later `declare` as global, and make actually global using a decorator, as described [in the docs](https://typescripttolua.github.io/docs/assigning-global-variables#registering-classes-with-a-decorator).\nHowever, using a decorator produces, in the compiled files, an assignation to `___exports` as the last instruction of the namespace definition.\n\n# Reproduction\nAside from the declaration and definition of a simple decorator (aptly named `Decorator`), I've made two files which both add a class to a namespace (`Repro`).\n**`WithoutDecorator.ts`**\n```ts\nnamespace Repro {\n export class WithoutDecorator {}\n}\n```\n\n**`WithDecorator.ts`**\n```ts\nnamespace Repro {\n @Decorator\n export class WithDecorator {}\n}\n```\n\nHere's the produced lua for those files:\n**`WithoutDecorator.lua`**\n```lua\nlocal ____lualib = require(\"lualib_bundle\")\nlocal __TS__Class = ____lualib.__TS__Class\nRepro = Repro or ({})\ndo\n Repro.WithoutDecorator = __TS__Class()\n local WithoutDecorator = Repro.WithoutDecorator\n WithoutDecorator.name = \"WithoutDecorator\"\n function WithoutDecorator.prototype.____constructor(self)\n end\nend\n```\n\n**`WithDecorator.lua`**\n```lua\nlocal ____lualib = require(\"lualib_bundle\")\nlocal __TS__Class = ____lualib.__TS__Class\nlocal __TS__Decorate = ____lualib.__TS__Decorate\nRepro = Repro or ({})\ndo\n Repro.WithDecorator = __TS__Class()\n local WithDecorator = Repro.WithDecorator\n WithDecorator.name = \"WithDecorator\"\n function WithDecorator.prototype.____constructor(self)\n end\n WithDecorator = __TS__Decorate(WithDecorator, WithDecorator, {Decorator}, {kind = \"class\", name = \"WithDecorator\"})\n ____exports.WithDecorator = WithDecorator -- [editor's note]: throws \"attempt to index global '____exports' (a nil value)\"\nend\n```\n\nTo test it for yourself, you can download this minimal reproduction repo: https://github.com/SirWrexes/tstl-decorator-bug.\nA `run.lua` file is provided to set the `package.path` to see results of compilation (inside `./lua/`) and require the two compiled sources.\n```sh\nnpm install\nnpx tstl\nlua ./run.lua\n```\n\n# Expected behaviour\nThis assignation should not happen. Behaviour should not be different with and without a decorator on the classes inside a namespace.\nThe namespace itself is global, and it is not exported from its file, so the source rightly doesn't have a local named `___exports` to assign to.","author":{"url":"https://github.com/SirWrexes","@type":"Person","name":"SirWrexes"},"datePublished":"2025-05-24T00:13:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/1634/TypeScriptToLua/issues/1634"}
| 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:6ab4a8e7-298d-ad49-213b-0ea9f06d211c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9F24:38B1A1:B2BE9C:F1E0A8:69731E9D |
| html-safe-nonce | 6cc63696b41ad913bf44f9d546f929306a8c2542afcc99797ab688b1ffb52615 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjI0OjM4QjFBMTpCMkJFOUM6RjFFMEE4OjY5NzMxRTlEIiwidmlzaXRvcl9pZCI6IjU1MDc2NTI3NDcwNTYzMjkyNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7c4e0213cd2880ab4672458a2d163792f8ae4a84d7266dd01264d6b46e67f7d2 |
| hovercard-subject-tag | issue:3087757367 |
| 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/TypeScriptToLua/TypeScriptToLua/1634/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b467cbd5c35291165b2eec7886916936e5f2003b80c2d857dd3d78f44e4a8a2c/TypeScriptToLua/TypeScriptToLua/issues/1634 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b467cbd5c35291165b2eec7886916936e5f2003b80c2d857dd3d78f44e4a8a2c/TypeScriptToLua/TypeScriptToLua/issues/1634 |
| og:image:alt | Description of the issue In my current project, I created a namespace that is split across different files with the goal of containing declarations of classes that I later declare as global, and ma... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SirWrexes |
| hostname | github.com |
| expected-hostname | github.com |
| None | 44ab3188c1dcfe3be0f9c3feca2e04e14fb79f120939ce2395e4f15ab96ec1d4 |
| turbo-cache-control | no-preview |
| go-import | github.com/TypeScriptToLua/TypeScriptToLua git https://github.com/TypeScriptToLua/TypeScriptToLua.git |
| octolytics-dimension-user_id | 44121206 |
| octolytics-dimension-user_login | TypeScriptToLua |
| octolytics-dimension-repository_id | 115876595 |
| octolytics-dimension-repository_nwo | TypeScriptToLua/TypeScriptToLua |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 115876595 |
| octolytics-dimension-repository_network_root_nwo | TypeScriptToLua/TypeScriptToLua |
| 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 | a5e2b48bd1260476599758f5d253b5d24092ab84 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width