Giter Club home page Giter Club logo

Comments (11)

kastermester avatar kastermester commented on July 24, 2024 1

It should be possible to use the TypeScript parser / emitter to inject the needed type annotations - although if you haven't used this API before it might be a bit tricky. I don't think it will be that costly using the TS API for this, it should be kinda fast - but obviously this would need to be verified.

from relay-compiler-language-typescript.

timjacobi avatar timjacobi commented on July 24, 2024 1

@alloy sounds good! I'm travelling this week but will get started on the PR after

from relay-compiler-language-typescript.

orta avatar orta commented on July 24, 2024

This makes sense, yeah, send a PR 👍

from relay-compiler-language-typescript.

cvle avatar cvle commented on July 24, 2024

I tried and I don't understand it quiet yet.. any hints to help me out?

from relay-compiler-language-typescript.

alloy avatar alloy commented on July 24, 2024

Hmm, yeah, this isn’t that easy right now. The plugin currently only operates on the types for the resulting GraphQL selections, not the artefact AST. The artefact AST comes in as just a large string from relay-compiler here, so the only way I could currently see this work is if we were to parse that text and regenerate it with the any typings, but that seems a little costly. Maybe we can determine if the noImplicitAny compiler flag is enabled and only then do the parsing/regeneration?

In any case, that’s where you should start with this.

from relay-compiler-language-typescript.

timjacobi avatar timjacobi commented on July 24, 2024

I hacked it together today.

function addAsAnyToObjectLiterals(oldSource){
    const ts = require("typescript");

    function transformer(context){
        return function transform(node){
            function visit(node){
                if(node.kind === ts.SyntaxKind.ObjectLiteralExpression){
                    return ts.createAsExpression(node, ts.createTypeReferenceNode('any', []));
                }
                return ts.visitEachChild(node, visit, context);
            }
            return ts.visitNode(node, visit);
        }   
    }

    const source  = ts.createSourceFile('', oldSource);

    const result = ts.transform(source, [transformer]);

    const printer = ts.createPrinter();
    const newSource = printer.printFile(result.transformed[0]);
    return newSource;
}

from relay-compiler-language-typescript.

alloy avatar alloy commented on July 24, 2024

Nice and simple 👌 And where are you adding this into your pipeline?

from relay-compiler-language-typescript.

sibelius avatar sibelius commented on July 24, 2024

should this be an option for relay compiler?

from relay-compiler-language-typescript.

timjacobi avatar timjacobi commented on July 24, 2024

@alloy I manually added it here in my project and it worked. If you want I can look into integrating it into this library.

from relay-compiler-language-typescript.

alloy avatar alloy commented on July 24, 2024

@sibelius I don’t think so, it’s a project wide TS setting, so my opinion is that we should fetch it from the project’s tsconfig (or perhaps there’s a runtime test for tsc options.)

@timjacobi Yeah that would be much appreciated! (And only do so when the option is enabled, as per above.)

from relay-compiler-language-typescript.

alloy avatar alloy commented on July 24, 2024

Closed by #83

from relay-compiler-language-typescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.