V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yazoox
V2EX  ›  程序员

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

  •  
  •   yazoox · 2020-05-04 15:55:26 +08:00 · 2602 次点击
    这是一个创建于 1452 天前的主题,其中的信息可能已经有所发展或是发生改变。

    学习使用 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)

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

    Image-20200504-5.jpg

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

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

    9 条回复    2020-05-06 11:15:28 +08:00
    xg4
        1
    xg4  
       2020-05-04 16:07:16 +08:00   ❤️ 1
    async,不是 aync
    rbe
        2
    rbe  
       2020-05-04 16:09:02 +08:00
    typescript.validate.enable 设为 false
    rbe
        3
    rbe  
       2020-05-04 16:11:07 +08:00   ❤️ 1
    @rbe #2 不过不建议关掉,像你这个明显拼写错误,检查出来是好事
    noe132
        4
    noe132  
       2020-05-04 16:26:08 +08:00
    async.
    yazoox
        5
    yazoox  
    OP
       2020-05-04 16:36:05 +08:00
    @xg4
    好吧,脑子越来越迟钝了......
    谢谢!
    chengxy
        6
    chengxy  
       2020-05-04 17:37:39 +08:00
    完了,删不掉了
    yuang
        7
    yuang  
       2020-05-04 21:11:20 +08:00 via Android   ❤️ 1
    推荐 spell checker 这个 VScode 插件,用于检查拼写错误
    xieranmaya
        8
    xieranmaya  
       2020-05-05 09:47:13 +08:00
    vscode 会自动对 js 执行 ts 的语法及类型检查
    ChineseCabbage
        9
    ChineseCabbage  
       2020-05-06 11:15:28 +08:00
    @chengxy 哈哈哈哈 这个心理跟我一模一样
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3884 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 04:15 · PVG 12:15 · LAX 21:15 · JFK 00:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.