diff --git a/src/TSHelper.ts b/src/TSHelper.ts index 6a9dc5a32..c8d749d8a 100644 --- a/src/TSHelper.ts +++ b/src/TSHelper.ts @@ -135,7 +135,7 @@ export function isStaticNode(node: ts.Node): boolean { export function isStringType(type: ts.Type, checker: ts.TypeChecker, program: ts.Program): boolean { if (type.symbol) { const baseConstraint = checker.getBaseConstraintOfType(type); - if (baseConstraint) { + if (baseConstraint && baseConstraint !== type) { return isStringType(baseConstraint, checker, program); } } @@ -158,7 +158,7 @@ export function isNumberType(type: ts.Type): boolean { export function isExplicitArrayType(type: ts.Type, checker: ts.TypeChecker, program: ts.Program): boolean { if (type.symbol) { const baseConstraint = checker.getBaseConstraintOfType(type); - if (baseConstraint) { + if (baseConstraint && baseConstraint !== type) { return isExplicitArrayType(baseConstraint, checker, program); } } diff --git a/test/unit/enum.spec.ts b/test/unit/enum.spec.ts index 383d9708f..bd40f2619 100644 --- a/test/unit/enum.spec.ts +++ b/test/unit/enum.spec.ts @@ -172,3 +172,27 @@ test("Const enum index identifier chain", () => { expect(result).toBe(4); }); + +test("enum toString", () => { + const code = ` + enum TestEnum { + A, + B, + C, + } + let test = TestEnum.A; + return test.toString();`; + expect(util.transpileAndExecute(code)).toBe(0); +}); + +test("enum concat", () => { + const code = ` + enum TestEnum { + A, + B, + C, + } + let test = TestEnum.A; + return test + "_foobar";`; + expect(util.transpileAndExecute(code)).toBe("0_foobar"); +});