From e8067f8934e27be80442ca249df04c5f9f556bd2 Mon Sep 17 00:00:00 2001 From: Zamiell <5511220+Zamiell@users.noreply.github.com> Date: Tue, 13 Oct 2020 18:18:31 -0400 Subject: [PATCH 1/3] better docs --- docs/advanced/writing-declarations.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/advanced/writing-declarations.md b/docs/advanced/writing-declarations.md index 2c359032..f07c5fb6 100644 --- a/docs/advanced/writing-declarations.md +++ b/docs/advanced/writing-declarations.md @@ -510,9 +510,9 @@ declare module "creator" { ### Operator Overloads -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. +Lua supports overloading of mathematical operators such as `+`, `-` or `*`. (This is done via adding a function to `__add`, `__sub`, `__mul`, and so forth.) 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. -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: +However, there is a workaround that works decently: if you declare a type as intersection type with number it will inherit all mathematical operators. For example: ```ts declare type Vector = number & { From f84c729149f7574e61855027e95c6b94255c9105 Mon Sep 17 00:00:00 2001 From: Zamiell <5511220+Zamiell@users.noreply.github.com> Date: Thu, 15 Oct 2020 00:20:01 -0400 Subject: [PATCH 2/3] pr feedback --- docs/advanced/writing-declarations.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/advanced/writing-declarations.md b/docs/advanced/writing-declarations.md index f07c5fb6..60cec470 100644 --- a/docs/advanced/writing-declarations.md +++ b/docs/advanced/writing-declarations.md @@ -510,9 +510,9 @@ declare module "creator" { ### Operator Overloads -Lua supports overloading of mathematical operators such as `+`, `-` or `*`. (This is done via adding a function to `__add`, `__sub`, `__mul`, and so forth.) 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. +Lua supports overloading of mathematical operators such as `+`, `-` or `*`, using [metatable methods](https://www.lua.org/manual/5.4/manual.html#2.4) such as `__add`, `__sub`, `__mul`, and so forth. 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. -However, there is a workaround that works decently: if you declare a type as intersection type with number it will inherit all mathematical operators. For example: +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: ```ts declare type Vector = number & { From 316d31bb7a5decb99ffb322551b233bfa1a38ace Mon Sep 17 00:00:00 2001 From: Zamiell <5511220+Zamiell@users.noreply.github.com> Date: Thu, 15 Oct 2020 00:22:30 -0400 Subject: [PATCH 3/3] pr feedback --- docs/advanced/writing-declarations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/advanced/writing-declarations.md b/docs/advanced/writing-declarations.md index 60cec470..581118d4 100644 --- a/docs/advanced/writing-declarations.md +++ b/docs/advanced/writing-declarations.md @@ -510,7 +510,7 @@ declare module "creator" { ### Operator Overloads -Lua supports overloading of mathematical operators such as `+`, `-` or `*`, using [metatable methods](https://www.lua.org/manual/5.4/manual.html#2.4) such as `__add`, `__sub`, `__mul`, and so forth. 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. +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. 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: