Skip to content

better docs #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 16, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/advanced/writing-declarations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `*`, 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.

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 an intersection type with `number`, it will inherit all mathematical operators. For example:

```ts
declare type Vector = number & {
Expand Down