Typescript compiler command (tsc) not working with tsconfig

I installed typescript globally ( npm install typescript -g )

Then created a folder, launched npm --init , then npm intall typescript --save-dev - installed typescript @ 2.1.4

In the folder I create 'helloworld.ts`

 var msg = 'Hello World'; console.log (msg); 

launched the tsc command with the file option - tsc helloworld.ts and saw that it was compiled in helloworld.js .

Next, I want to use tsconfig.json, so I run tsc --init - this does not work, says the Unknown option 'init'

I say, well, let me try adding tsconfig.json manually and add it to the root of the folder, as shown below:

 { "compilerOptions": { "target": "es5" }, "files": [ "helloworld.ts" ] } 

and I run tsc on the command line, but it will not work and displays me the syntax, example and parameters of how to use tsc Syntax: tsc [options] [file] ...

What's wrong?

where tsc 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 
+11
source share
2 answers

This is problem:

 C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\tsc.exe C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\tsc.js 

remove-update-remove-get-rid-off: deprecated Visual Studio extensions ...

or remove it from the path ...

or rename the folder to confirm the problem ... then nuke it :)

check what happens if you run:

 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 need to install typescript a local project if the module you depend on depends on it
you need to use the compiler function in your own code

you need to use a different version than the globally installed

for init:

 tsc --init 

for compilation

a 'project' (based on tsconfig.json):

 tsc -p . 

where . mean here

to compile a "different" project

 tsc -p other/tsconfig.json 

Additional Help

+18
source

What I did to set up the Typescript version of the tsc command on my Windows system was:

Editing system environment PATH variable

Delete Typescript 1.0 path here. (Run button-> Type: environment variables, click on the option (the English version of Windows is here) and select the PATH system environment variable).

After I entered:

npm link typewriting

And then I used the refreshenv Chocolatey command to update the system PATH environment variable that I configured.

refreshenv

After 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 the Typescript course using this version.

0
source

Source: https://habr.com/ru/post/1013450/


All Articles