Skip to content

Fix #115: typeof usage on object types - #116

Open
SebastienGllmt wants to merge 2 commits into
woutervh-:masterfrom
SebastienGllmt:fix-issue-115
Open

Fix #115: typeof usage on object types#116
SebastienGllmt wants to merge 2 commits into
woutervh-:masterfrom
SebastienGllmt:fix-issue-115

Conversation

@SebastienGllmt

@SebastienGllmt SebastienGllmt commented Nov 13, 2021

Copy link
Copy Markdown

See #115 for the description of the problem and how I got to the solution

This is the final generated code which looks correct 👍

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Status = void 0;
const assert = require("assert");
const index_1 = require("../index");
/* https://github.com/woutervh-/typescript-is/issues/115 */
exports.Status = {
    enable: 'enable',
    disable: 'disable'
};
describe('is', () => {
    describe('Accessing generic member of a type', () => {
        it('should return true for the right member', () => {
            assert.deepStrictEqual(index_1.is({ status: exports.Status.enable }, object => { function _1(object) { ; if (object !== "enable")
                return {};
            else
                return null; } function _0(object) { ; if (typeof object !== "object" || object === null || Array.isArray(object))
                return {}; {
                if ("status" in object) {
                    var error = _1(object["status"]);
                    if (error)
                        return error;
                }
                else
                    return {};
            } return null; } return _0(object); }), true);
        });
        it('should return false for the wrong member', () => {
            assert.deepStrictEqual(index_1.is({ status: exports.Status.disable }, object => { function _1(object) { ; if (object !== "enable")
                return {};
            else
                return null; } function _0(object) { ; if (typeof object !== "object" || object === null || Array.isArray(object))
                return {}; {
                if ("status" in object) {
                    var error = _1(object["status"]);
                    if (error)
                        return error;
                }
                else
                    return {};
            } return null; } return _0(object); }), false);
        });
    });
});

@SebastienGllmt SebastienGllmt changed the title Fix #115: indexing type with generic Fix #115: typeof usage on object types Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant