Skip to content

Commit b4d4504

Browse files
committed
Changed typeof returning object instead of table
1 parent 0d0f81b commit b4d4504

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/Transpiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ export abstract class LuaTranspiler {
11321132

11331133
public transpileTypeOfExpression(node: ts.TypeOfExpression): string {
11341134
const expression = this.transpileExpression(node.expression);
1135-
return `type(${expression})`;
1135+
return `type(${expression}) == "table" and "object" or type(${expression})`;
11361136
}
11371137

11381138
// Transpile a variable statement

test/unit/typechecking.spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,23 @@ export class OverloadTests {
4242
const lua = util.transpileString(`return typeof ${inp};`);
4343
const result = util.executeLua(lua);
4444

45-
Expect(result).toBe("table");
45+
Expect(result).toBe("object");
4646
}
4747

4848
@Test("typeof class instance")
4949
public typeofClassInstance() {
5050
const lua = util.transpileString(`class myClass {} let inst = new myClass(); return typeof inst;`);
5151
const result = util.executeLua(lua);
5252

53-
Expect(result).toBe("table");
53+
Expect(result).toBe("object");
54+
}
55+
56+
@Test("typeof function")
57+
public typeofFunction() {
58+
const lua = util.transpileString(`return typeof (() => 3);`);
59+
const result = util.executeLua(lua);
60+
61+
Expect(result).toBe("function");
5462
}
5563

5664
@TestCase("null")

0 commit comments

Comments
 (0)