Typescript Interface SyntaxError: Unexpected identifier at interface name

I'm new to Typescript and I'm still figuring my way out, I searched this problem everywhere otherwise I wont be asking this question. I have a SyntaxError at the interface name and don't know how to solve it. Here is my short code:

interface Cars {
    name:string
    model:string
    topSpeed:number
    colors:string[]
    speedPrint(carSpeed:number):void
}

class BMW implements Cars{
    name = 'BMW X6'
    model = 'S'
    topSpeed = 320
    colors = ['cobalt red','phantom blue','white']
    speedPrint(topSpeed:number):void{
        console.log(`My car top speed is ${topSpeed}`)
    }
}

and this is the error:

app.ts:1
interface Cars {
          ^^^^

SyntaxError: Unexpected identifier
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

Solution 1:

I was facing the same error but I did the following and it works:

  1. Install ts by typing this command in the terminal npm install -g typescript
  2. After this type tsc filename.ts
  3. Then node ./file.js (not ts) and see what gonna happen on the terminal