I recently started learning Typescript and encountered a slow compilation issue while following a tutorial on Youtube. When I run tsc myfile.ts
, it takes about 40 seconds to compile, even though my file is short with just basic Javascript code for understanding type definitions in Typescript. Interestingly, the instructor's file compiles in a second, but I have to wait much longer. How can I speed up the compilation process?
To install Typescript globally, I used the command npm install -g typescript
. My project does not contain any .tsconfig
files; it only consists of a single .ts
file and a simple index.html
file.
It may not be relevant, but here is the content of the .ts file that I am compiling:
function add(num1: number, num2: number, showResult: boolean, phrase: string) {
const result = num1 + num2;
if (showResult) {
console.log(phrase + result)
} else {
return result
}
}
const number1 = 5;
const number2 = 2.5
const printResult = true;
const resultPhrase = 'Result is: '
const result = add(number1, number2, printResult, resultPhrase);
Additionally, I am using a Macbook Pro with an M1 chip which might provide some context.
Thank you!
Edit: The file eventually compiles, but the main issue remains the excessive time it takes to complete the process.