• 请不要在回答技术问题时复制粘贴 AI 生成的内容
gzf6
V2EX  ›  程序员

在 vscode 中写 ts 报错:无法重新声明块范围变量“a”。

  •  
  •   gzf6 · Apr 14, 2018 · 11170 views
    This topic created in 3127 days ago, the information mentioned may be changed or developed.

    开发工具 VSCode 编写 ts 文件
    代码如下:

    let a:string = 'abc';
    

    编译时出现:

    无法重新声明块范围变量“ a ”
    

    请教如何处理?

    4 replies  •  2020-04-24 09:50:34 +08:00
    Lxxyx
    Lxxyx
    Apr 14, 2018
    1
    应该是你之前写了一个 let a。
    gzf6
    gzf6
    OP
    Apr 14, 2018
    2
    @Lxxyx 必须把 JavaScript 文件删除,重新编译才行;要是之前编译的 JavaScript 还在,直接在 ts 上把 let a 删除,再写 let a 就会报错。
    Mitt
    Mitt
    Apr 14, 2018 via iPhone
    3
    顺便提一下 :后面要加空格 tslint 会报 error 的
    jl1014171068
    jl1014171068
    Apr 24, 2020
    4
    - https://www.jianshu.com/p/78268bd9af0a
    - 解决方法:末尾添加 export {}
    - 在 Typescript 中,只要文件存在 import 或 export 关键字,都被视为 module
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1455 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:58 · PVG 06:58 · LAX 14:58 · JFK 17:58
    ♥ Do have faith in what you're doing.