Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to make TypeScript honor tabs?

Tags:

typescript

It seems that typescript ignores tab settings for JavaScript files and inserts spaces instead of tabs in the generated js file.

Is there a setting to force tabs instead of spaces?

P.S. Using VS 2013 Update 4

like image 620
Roman Royter Avatar asked Jan 16 '15 22:01

Roman Royter


3 Answers

The indentation emitted by the compiler appears to be hardcoded.

So no, you can't configure it.

like image 55
Journey Avatar answered Nov 18 '22 23:11

Journey


The workaround solution from [S-YOU] in typescript issues thread might be useful until typescript team allow to modify through tsconfig.json:

https://github.com/Microsoft/TypeScript/issues/4042

For those who just want to change the output to tab, you can patch typescript.js after you install.

sed -i 's/"    "/"\\t"/g' node_modules/typescript/lib/typescript.js

% grep "indentStrings =" node_modules/typescript -R

node_modules/typescript/lib/typescriptServices.js: var indentStrings = ["", "    "];
node_modules/typescript/lib/typescript.js: var indentStrings = ["", "\t"];
node_modules/typescript/lib/tsserverlibrary.js: var indentStrings = ["", "    "];
node_modules/typescript/lib/tsserver.js: var indentStrings = ["", "    "];
node_modules/typescript/lib/tsc.js: var indentStrings = ["", "    "];

if you want to change indentString to something you prefer change in those files the 2nd string to whatever you want.

like image 37
Kumar Sucom Avatar answered Nov 19 '22 00:11

Kumar Sucom


Old issue but since this is still relevant, I find that adding && prettier --write ./dist to your build command would be a better option, since TypeScript output doesn't seem to be well-formatted even if you patch the TypeScript library files. Plus, when you deploy to Heroku, the deployment environment handles package installation and build; so this gives you control over the output even then.

like image 1
Mr. X Avatar answered Nov 19 '22 01:11

Mr. X