小编you*_*ziz的帖子

Typescript 接口语法错误:接口名称中出现意外的标识符

我是 Typescript 的新手,我仍在寻找出路,我到处搜索这个问题,否则我不会问这个问题。我在接口名称处出现语法错误,不知道如何解决。这是我的简短代码:

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}`)
    }
}
Run Code Online (Sandbox Code Playgroud)

这是错误:

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
Run Code Online (Sandbox Code Playgroud)

interface typescript

6
推荐指数
2
解决办法
7984
查看次数

标签 统计

interface ×1

typescript ×1