Skip to content

Commit 4e858e9

Browse files
authored
better docs (#16)
* better docs * pr feedback * pr feedback
1 parent 0bcce31 commit 4e858e9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

docs/advanced/writing-declarations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,9 @@ declare module "creator" {
510510

511511
### Operator Overloads
512512

513-
Lua supports overloading of mathematical operators such as `+`, `-` or `*`. Since TypeScript does not support operator overloading in its type system this is hard to replicate. Unfortunately this is not something that can be fixed properly right now without forking off our custom TypeScript version.
513+
Lua supports overloading of mathematical operators such as `+`, `-` or `*`. This is performed using the [metatable methods](https://www.lua.org/manual/5.4/manual.html#2.4) `__add`, `__sub`, `__mul`, `__div`, and `__unm`. Since TypeScript does not support operator overloading in its type system, this feature is hard to replicate. Unfortunately, this is not something that can be fixed properly right now without forking off our custom TypeScript version.
514514

515-
There is however a workaround that works decently: If you declare a type as intersection type with number it will inherit all mathematical operators. For example:
515+
However, there is a workaround that works decently: if you declare a type as an intersection type with `number`, it will inherit all mathematical operators. For example:
516516

517517
```ts
518518
declare type Vector = number & {

0 commit comments

Comments
 (0)