-
Notifications
You must be signed in to change notification settings - Fork 21
added operator map types to language extensions #24
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
Conversation
docs/advanced/language-extensions.md
Outdated
| - LuaFloorDivision / LuaFloorDivisionMethod (`a // b`, only when targeting Lua 5.3 or later) | ||
| - LuaNegation / LuaNegationMethod (`-x`) | ||
| - Bitwise operators (only when targeting Lua 5.3 or later) | ||
| - BitwiseAnd / BitwiseAndMethod (`a & b`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are Bitwise ops not prefixed with Lua?
| However, there are workarounds that work decently. | ||
|
|
||
| One method is to declare a type as an intersection type with `number`. It will then inherit all mathematical operators. For example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| However, there are workarounds that work decently. | |
| One method is to declare a type as an intersection type with `number`. It will then inherit all mathematical operators. For example: | |
| However, there are two possible workarounds. The first one is to declare a type as an intersection type with `number`. It will then inherit all mathematical operators. Keep in mind that this is only partially type safe and may require some additional casting. | |
| Example: |
| const d = v3.dot(v2); | ||
| ``` | ||
|
|
||
| There are also language extensions that allow declaring special functions which will transpile to operators. For example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| There are also language extensions that allow declaring special functions which will transpile to operators. For example: | |
| The second option was added in version [0.38.0](https://github.com/TypeScriptToLua/TypeScriptToLua/blob/master/CHANGELOG.md#0380). You can now use [language extensions](https://typescripttolua.github.io/docs/advanced/language-extensions) that allow declaring special functions which will transpile to operators. This will be completely type safe if the operators are declared correctly. | |
| Example: |
Maybe mention this one first?
I think this should be the recommended variant.
docs/advanced/language-extensions.md
Outdated
| export const mul: LuaMultiplication<Vector, Vector, number> & LuaMultiplication<Vector, number, Vector>; | ||
| } | ||
|
|
||
| const dot = Vector.mul(a, b); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nice to add types to these consts to demonstrate the point, ie const dot: number = and const scaled: Vector =
| const d = v3.dot(v2); | ||
| ``` | ||
|
|
||
| There are also language extensions that allow declaring special functions which will transpile to operators. For example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like duplicate information, couldn't you just refer to the language extensions page? ./language-extensions.md#operator-map-types should do the trick
No description provided.