Skip to content

Commit a39cb12

Browse files
authored
Documentation for @customName (#170)
* Documentation for `@customName` * Improve `@customName` docs * Update compiler-annotations.md
1 parent 673b0d8 commit a39cb12

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

docs/advanced/compiler-annotations.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,61 @@ local module = require("mymodule");
174174

175175
</SideBySide>
176176

177+
## @customName
178+
179+
**Target elements:** Any declaration statement
180+
181+
This decorator can be used to rename variables, identifiers, etc. Meaning that you can name something `x` in your Typescript environment, but then have it compile under the name `y`.
182+
183+
This can be quite handy to get around some reserved keywords in Typescript, which you might need/want to use in Lua.
184+
185+
**Example**
186+
187+
<SideBySide>
188+
189+
```typescript title=input.ts
190+
/** @customName test2 */
191+
function test() {}
192+
193+
test();
194+
```
195+
196+
```lua title=output.lua
197+
...
198+
function test2(self)
199+
end
200+
test2(_G)
201+
```
202+
203+
</SideBySide>
204+
205+
<SideBySide>
206+
207+
```typescript title=input.ts
208+
/** @customName Test2 **/
209+
namespace Test {
210+
/** @customName Func2 **/
211+
export function Func(): string {
212+
return "hi";
213+
}
214+
}
215+
216+
Test.Func();
217+
```
218+
219+
```lua title=output.lua
220+
...
221+
Test2 = Test2 or ({})
222+
do
223+
function Test2.Func2(self)
224+
return "hi"
225+
end
226+
end
227+
Test2:Func2()
228+
```
229+
230+
</SideBySide>
231+
177232
## @noSelf
178233

179234
**Target elements:** `declare class`, `(declare) interface` or `declare namespace`

0 commit comments

Comments
 (0)