Typescript compiler API: print PropertySignature on a single lineWhat is TypeScript and why would I use it in place of JavaScript?get and set in TypeScriptAre strongly-typed functions as parameters possible in TypeScript?TypeScript Converting a String to a numberTypescript: Interfaces vs TypesTypescript object literal “this” keywordHow to initialize a TypeScript object from a list of constructors? (Maybe: Mapped Type? Type operator for opposite of `typeof`?)TypeScript generic contraints with extending and default parametersTypescript return type possibilities of a resolved promiseReturning a Type as a Variable in TypeScript

What exactly makes a General Products hull nearly indestructible?

What causes long-running disputes over sovereignty?

Where to place an artificial gland in the human body?

Knights fighting a steam locomotive they believe is a dragon

Iterate over non-const variables in C++

This message is flooding my syslog, how to find where it comes from?

Is it legal to use cash pulled from a credit card to pay the monthly payment on that credit card?

How were the LM astronauts supported during the moon landing and ascent? What were the max G's on them during these phases?

What to do when you reach a conclusion and find out later on that someone else already did?

powerhouse of ideas

What do teaching faculty do during semester breaks?

Can two figures have the same area, perimeter, and same number of segments have different shape?

Is it legal for private citizens to "impound" e-scooters?

Does academia have a lazy work culture?

expansion with *.txt in the shell doesn't work if no .txt file exists

401(k) investment after being fired. Do I own it?

How do we explain the E major chord in this progression?

How to write a sincerely religious protagonist without preaching or affirming or judging their worldview?

Send a single HTML email from Thunderbird, overriding the default "plain text" setting

Is it better to memorize verb's 1st person perfect tense?

How can I tell if there was a power cut while I was out?

How can I prevent corporations from growing their own workforce?

Why no ";" after "do" in sh loops?

Convert a string like 4h53m12s to a total number of seconds in JavaScript



Typescript compiler API: print PropertySignature on a single line


What is TypeScript and why would I use it in place of JavaScript?get and set in TypeScriptAre strongly-typed functions as parameters possible in TypeScript?TypeScript Converting a String to a numberTypescript: Interfaces vs TypesTypescript object literal “this” keywordHow to initialize a TypeScript object from a list of constructors? (Maybe: Mapped Type? Type operator for opposite of `typeof`?)TypeScript generic contraints with extending and default parametersTypescript return type possibilities of a resolved promiseReturning a Type as a Variable in TypeScript






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm trying to generate a function that returns an object-literal type (not sure if that's the correct term). I currently use the following:



ts.createFunctionDeclaration(
undefined, //decorators
[], //modifiers
undefined, //asterisk
'foo',
undefined, //name
[], //parameters

ts.createTypeLiteralNode( //return type
[
ts.createPropertySignature(
undefined, //modifiers
ts.createIdentifier('bar'),
undefined, //question token
ts.createTypeReferenceNode(
'string',
undefined //generics
),
undefined //initializer
),
ts.createPropertySignature(
undefined, //modifiers
ts.createIdentifier('baz'),
undefined, //question token
ts.createTypeReferenceNode(
'string',
undefined //generics
),
undefined //initializer
)
]
),

ts.createBlock([
//some interesting statements
])
);


This generates this code:



function foo(): 
bar: string;
baz: string;

//interesting statements



It works, but I'd like the return type literal to be on a single line like this:



function foo(): bar: string, baz: string 
//interesting statements



Is this possible using just the Typescript compiler API, or do I need to use an external linter/formatter?










share|improve this question




























    1















    I'm trying to generate a function that returns an object-literal type (not sure if that's the correct term). I currently use the following:



    ts.createFunctionDeclaration(
    undefined, //decorators
    [], //modifiers
    undefined, //asterisk
    'foo',
    undefined, //name
    [], //parameters

    ts.createTypeLiteralNode( //return type
    [
    ts.createPropertySignature(
    undefined, //modifiers
    ts.createIdentifier('bar'),
    undefined, //question token
    ts.createTypeReferenceNode(
    'string',
    undefined //generics
    ),
    undefined //initializer
    ),
    ts.createPropertySignature(
    undefined, //modifiers
    ts.createIdentifier('baz'),
    undefined, //question token
    ts.createTypeReferenceNode(
    'string',
    undefined //generics
    ),
    undefined //initializer
    )
    ]
    ),

    ts.createBlock([
    //some interesting statements
    ])
    );


    This generates this code:



    function foo(): 
    bar: string;
    baz: string;

    //interesting statements



    It works, but I'd like the return type literal to be on a single line like this:



    function foo(): bar: string, baz: string 
    //interesting statements



    Is this possible using just the Typescript compiler API, or do I need to use an external linter/formatter?










    share|improve this question
























      1












      1








      1








      I'm trying to generate a function that returns an object-literal type (not sure if that's the correct term). I currently use the following:



      ts.createFunctionDeclaration(
      undefined, //decorators
      [], //modifiers
      undefined, //asterisk
      'foo',
      undefined, //name
      [], //parameters

      ts.createTypeLiteralNode( //return type
      [
      ts.createPropertySignature(
      undefined, //modifiers
      ts.createIdentifier('bar'),
      undefined, //question token
      ts.createTypeReferenceNode(
      'string',
      undefined //generics
      ),
      undefined //initializer
      ),
      ts.createPropertySignature(
      undefined, //modifiers
      ts.createIdentifier('baz'),
      undefined, //question token
      ts.createTypeReferenceNode(
      'string',
      undefined //generics
      ),
      undefined //initializer
      )
      ]
      ),

      ts.createBlock([
      //some interesting statements
      ])
      );


      This generates this code:



      function foo(): 
      bar: string;
      baz: string;

      //interesting statements



      It works, but I'd like the return type literal to be on a single line like this:



      function foo(): bar: string, baz: string 
      //interesting statements



      Is this possible using just the Typescript compiler API, or do I need to use an external linter/formatter?










      share|improve this question














      I'm trying to generate a function that returns an object-literal type (not sure if that's the correct term). I currently use the following:



      ts.createFunctionDeclaration(
      undefined, //decorators
      [], //modifiers
      undefined, //asterisk
      'foo',
      undefined, //name
      [], //parameters

      ts.createTypeLiteralNode( //return type
      [
      ts.createPropertySignature(
      undefined, //modifiers
      ts.createIdentifier('bar'),
      undefined, //question token
      ts.createTypeReferenceNode(
      'string',
      undefined //generics
      ),
      undefined //initializer
      ),
      ts.createPropertySignature(
      undefined, //modifiers
      ts.createIdentifier('baz'),
      undefined, //question token
      ts.createTypeReferenceNode(
      'string',
      undefined //generics
      ),
      undefined //initializer
      )
      ]
      ),

      ts.createBlock([
      //some interesting statements
      ])
      );


      This generates this code:



      function foo(): 
      bar: string;
      baz: string;

      //interesting statements



      It works, but I'd like the return type literal to be on a single line like this:



      function foo(): bar: string, baz: string 
      //interesting statements



      Is this possible using just the Typescript compiler API, or do I need to use an external linter/formatter?







      typescript typescript-compiler-api






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 26 at 17:11









      superbadcodemonkeysuperbadcodemonkey

      878 bronze badges




      878 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Try setting the emit flag EmitFlags.SingleLine on the type literal node:



          const typeLiteralNode = ts.createTypeLiteralNode(...);
          ts.setEmitFlags(typeLiteralNode, EmitFlags.SingleLine);


          emitTypeLiteral in emitter.ts seems to indicate it's possible to do this.






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55362724%2ftypescript-compiler-api-print-propertysignature-on-a-single-line%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Try setting the emit flag EmitFlags.SingleLine on the type literal node:



            const typeLiteralNode = ts.createTypeLiteralNode(...);
            ts.setEmitFlags(typeLiteralNode, EmitFlags.SingleLine);


            emitTypeLiteral in emitter.ts seems to indicate it's possible to do this.






            share|improve this answer



























              0














              Try setting the emit flag EmitFlags.SingleLine on the type literal node:



              const typeLiteralNode = ts.createTypeLiteralNode(...);
              ts.setEmitFlags(typeLiteralNode, EmitFlags.SingleLine);


              emitTypeLiteral in emitter.ts seems to indicate it's possible to do this.






              share|improve this answer

























                0












                0








                0







                Try setting the emit flag EmitFlags.SingleLine on the type literal node:



                const typeLiteralNode = ts.createTypeLiteralNode(...);
                ts.setEmitFlags(typeLiteralNode, EmitFlags.SingleLine);


                emitTypeLiteral in emitter.ts seems to indicate it's possible to do this.






                share|improve this answer













                Try setting the emit flag EmitFlags.SingleLine on the type literal node:



                const typeLiteralNode = ts.createTypeLiteralNode(...);
                ts.setEmitFlags(typeLiteralNode, EmitFlags.SingleLine);


                emitTypeLiteral in emitter.ts seems to indicate it's possible to do this.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 26 at 17:39









                David SherretDavid Sherret

                57.8k18 gold badges133 silver badges133 bronze badges




                57.8k18 gold badges133 silver badges133 bronze badges


















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55362724%2ftypescript-compiler-api-print-propertysignature-on-a-single-line%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript