|Feature||Lua 5.1||Lua 5.2||Lua 5.3||LuaJIT|
Below are some of the cases where resulting Lua intentionally behaves different from compiled JS.
One of TypeScript's design goals is not using type information to affect program runtime behavior. Though this has many advantages (such as gradual typing), TypeScriptToLua uses type information extensively. This allows us to emit a much more optimized, portable, and correct Lua code.
TypeScriptToLua makes no difference between
=== when compiling to Lua, treating all comparisons as strict (
Array.prototype.length is translated to Lua's
list.length and Lua's
#list. The transpiler does not do anything to remedy these differences, so when working with lists, the transpiled Lua will use the standard Lua conventions. Generally speaking, the situation where these differences occur happen when adding/removing items to a list in a hacky way, or when setting list items to
Safe (no difference):
Differences might occur:
Even though iterating over object keys with
Note: If a specific order is required, it is better to use ordered collections like lists instead.
Iterating an array with
for ... in#