ts-auto-mock icon indicating copy to clipboard operation
ts-auto-mock copied to clipboard

[RFC] feature(transformer): Conditional typing

Open martinjlowm opened this issue 4 years ago • 0 comments

edit: After a recent (write-up) discussion (see https://www.notion.so/RFC-Overload-c5a832ca51654f58a5019bf5507013a7), this PR is on hold. It'll add too much complexity in its current state and the project is not ready for such big changes. Feel free to leave a comment here if you have ideas or proposals for how we can approach this.


edit: Moved this PR into draft. It's blocked by a solution to the issue discussed in #313 on how to pass around mock and function identities.

This PR is based on the work done in #303 and #313 and will emit conditional code (from the test) as follows.

ɵRepository.ɵRepository.instance.registerFactory("@TypeName_1", function (t) { return (function () {
    var __0 = (function () {
        var generic = t.find(function (generic) {
            return generic.i.indexOf("@TypeName_1T") >= 0;
        });
        if (generic) {
            return generic.w();
        }
        return null;
    })();
    if (typeof __0 === "string")
        return "string";
    else if (typeof __0 === "number")
        return "number";
    else if (typeof __0 === "boolean")
        return "boolean";
    else if (typeof __0 === "undefined")
        return "undefined";
    else if ((__0 && __0.__ident) === "AA==")
        return "function";
    else if ((__0 && __0.__ident) === "SQ==")
        return "function";
    else if ((__0 && __0.__ident) === "XA==")
        return "function";
    else
        return "object";
})(); });

This is based on the test case on the unsupported types page. Thorough tests are to be added.

martinjlowm avatar May 10 '20 21:05 martinjlowm