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;
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
add a comment |
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
add a comment |
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
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
typescript typescript-compiler-api
asked Mar 26 at 17:11
superbadcodemonkeysuperbadcodemonkey
878 bronze badges
878 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
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
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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