I installed typescript globally ( npm install typescript -g
)
Then created a folder, ran npm --init
, then npm intall typescript --save-dev
- it installed [email protected]
In the folder , I create 'helloworld.ts`
var msg = 'Hello World';
console.log (msg);
ran tsc command with file option - tsc helloworld.ts
and see it compiled to helloworld.js
.
Next, I want to use tsconfig.json, so I run tsc --init
- this doesn't work, says Unknown option 'init'
i say alright, let me try adding tsconfig.json manually and add it in the folder root as below:
{
"compilerOptions": {
"target": "es5"
},
"files": [
"helloworld.ts"
]
}
and I run tsc
on command prompt, but it won't work and outputs me the syntax, example and options of how to use tsc Syntax: tsc [options] [file] ...
whats wrong?
where tsc
gives below:
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\tsc.exe
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\tsc.js
C:\Users\Kap\AppData\Roaming\npm\tsc
C:\Users\Kap\AppData\Roaming\npm\tsc.cmd
this is the problem:
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\tsc.exe
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\tsc.js
uninstall-update-remove-get-rid-off: Visual Studio outdated extensions...
or remove it from the path ...
or rename the folder to confirm the problem ... then nuke it :)
check what happens if you do:
md x
cd x
tsc --init
npm init -y
npm link typescript
echo console.log('it works') > index.ts
tsc -p .
node .
should output
it works
also.
I'll need install typescript local to the project if
a module you depend on, depends on it
you need to use a compiler feature in "your" code
you need to use a different version than the installed globally
tsc --init
a 'project' (based on tsconfig.json):
tsc -p .
where . means here
tsc -p other/tsconfig.json
More help
The issue I had was that I wasn't getting any errors but I also wasn't getting any output.
I realised that I had "noEmit": true
in my tsconfig.json file.
When I removed that it worked as expected :)
What I did to adjust Typescript version of tsc command on my Windows system was:
Removing the Typescript 1.0 path here. (Start button-> Type : environment variables, click on the option (English version of Windows here) and choosing the system environment variable PATH).
Afterwards I entered:
npm link typescript
And then I used the refreshenv command of Chocolatey to refresh the system PATH environment variable I adjusted.
refreshenv
After then running the command: tsc -v I got: Version 2.2.1
The current version of Typescript is 3.5+, but I globally installed Typescript 2.2.1 because I am following a Typescript course using that version.
Every single time I've ended up here after Googling "typescript tsc no output" it's for the same reason. Since this has definitely happened more than once I'll throw my answer into the ring too.
Every time this has happened to me it's because TypeScript is configured with composite: true
and I deleted the output directory (the one set as outDir
in tsconfig
), but didn't delete the tsconfig.tsbuildinfo
file.
This leads TypeScript to assume that the output doesn't need updating, because the timestamp on the tsbuildinfo
file says that the last build was after all the files were modified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With