Skip to content
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

Fix #115: typeof usage on object types #116

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

SebastienGllmt
Copy link

@SebastienGllmt SebastienGllmt commented Nov 13, 2021

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