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

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

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