V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
windzzm

ts 如何书写 console.log([...'hello'])?

  •  
  •   windzzm · Oct 8, 2022 · 2698 views
    This topic created in 1297 days ago, the information mentioned may be changed or developed.

    es6 可以正常支持,但是在 ts 中这样写会报错

    Supplement 1  ·  Oct 8, 2022
    tsc 提示 error TS2461: Type '"hello"' is not an array type.
    而 ts-node 命令可以正常运行

    这是哪里的问题?
    Supplement 2  ·  Oct 8, 2022
    14 replies    2022-11-22 06:23:00 +08:00
    windzzm
        1
    windzzm  
    OP
       Oct 8, 2022
    tsc 编译后提示:error TS2461: Type '"hello wold"' is not an array type.
    cyrbuzz
        2
    cyrbuzz  
       Oct 8, 2022
    换下版本 4.6.4 没报错,不然 ts-ignore 。
    windzzm
        3
    windzzm  
    OP
       Oct 8, 2022
    @cyrbuzz 我的版本是 4.8.4
    Trim21
        4
    Trim21  
       Oct 8, 2022
    Type '"hello"' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
    windzzm
        5
    windzzm  
    OP
       Oct 8, 2022
    @Trim21 target 设置为 es2016 的
    Trim21
        6
    Trim21  
       Oct 8, 2022 via Android
    @windzzm 我设置成 ES2015 就没报错了,没法复现你说的情况
    ifdef
        7
    ifdef  
       Oct 8, 2022
    windzzm
        9
    windzzm  
    OP
       Oct 8, 2022
    windzzm
        10
    windzzm  
    OP
       Oct 8, 2022
    @ifdef 在线的是没问题,我本地 ts-node 也没问题,就是 tsc 有问题
    ifdef
        11
    ifdef  
       Oct 8, 2022
    加一行这个呢 "use strict";
    @windzzm
    Trim21
        12
    Trim21  
       Oct 8, 2022 via Android
    @windzzm 用 tsc $filename 指定文件名转译的时候 tsconfig.json 是无效的
    windzzm
        13
    windzzm  
    OP
       Oct 8, 2022
    @Trim21 原来如此,多谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   948 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 21:46 · PVG 05:46 · LAX 14:46 · JFK 17:46
    ♥ Do have faith in what you're doing.