为什么我的.js 文件,会报错提示 TypeScript 1005 的问题?

2020-05-04 15:55:26 +08:00
 yazoox

学习使用 express server,于是建立 了一个新项目 package.json

{
    "name": "@my/server",
    "version": "1.0.0",
    "scripts": {
        "server": "node src/express-server.js"
    },
    "dependencies": {
        "express": "^4.17.1",
        "lodash": "^4.17.15"
    }
}

然后新建立了一个 baseDB.js (是一个 js 文件,不是 ts 文件)


class baseDB {
    constructor() {
        this.items = [];
    }

    load() {
        // will be implemented in the sub-class
        console.log("will be implemented in the sub-class");
    }

    aync save() {
        console.log("will be implemented in the sub-class");
    }
}

然后有关键字aync的那一行,就提示有错误。';' expected.ts(1005)

大家有没有碰到类似的问题?谢谢!

p.s. https://github.com/microsoft/vscode/issues/54261

VSCode github 上面曾经有类似的问题,2018 年报的,可惜,那个帖子不了了之了......

2611 次点击
所在节点    程序员
9 条回复
xg4
2020-05-04 16:07:16 +08:00
async,不是 aync
rbe
2020-05-04 16:09:02 +08:00
typescript.validate.enable 设为 false
rbe
2020-05-04 16:11:07 +08:00
@rbe #2 不过不建议关掉,像你这个明显拼写错误,检查出来是好事
noe132
2020-05-04 16:26:08 +08:00
async.
yazoox
2020-05-04 16:36:05 +08:00
@xg4
好吧,脑子越来越迟钝了......
谢谢!
chengxy
2020-05-04 17:37:39 +08:00
完了,删不掉了
yuang
2020-05-04 21:11:20 +08:00
推荐 spell checker 这个 VScode 插件,用于检查拼写错误
xieranmaya
2020-05-05 09:47:13 +08:00
vscode 会自动对 js 执行 ts 的语法及类型检查
ChineseCabbage
2020-05-06 11:15:28 +08:00
@chengxy 哈哈哈哈 这个心理跟我一模一样

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/668458

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX