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

2022 年 10 月 8 日
 windzzm

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

2628 次点击
所在节点    TypeScript
14 条回复
windzzm
2022 年 10 月 8 日
tsc 编译后提示:error TS2461: Type '"hello wold"' is not an array type.
cyrbuzz
2022 年 10 月 8 日
换下版本 4.6.4 没报错,不然 ts-ignore 。
windzzm
2022 年 10 月 8 日
@cyrbuzz 我的版本是 4.8.4
Trim21
2022 年 10 月 8 日
Type '"hello"' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
windzzm
2022 年 10 月 8 日
@Trim21 target 设置为 es2016 的
Trim21
2022 年 10 月 8 日
@windzzm 我设置成 ES2015 就没报错了,没法复现你说的情况
ifdef
2022 年 10 月 8 日
ifdef
2022 年 10 月 8 日
windzzm
2022 年 10 月 8 日
windzzm
2022 年 10 月 8 日
@ifdef 在线的是没问题,我本地 ts-node 也没问题,就是 tsc 有问题
ifdef
2022 年 10 月 8 日
加一行这个呢 "use strict";
@windzzm
Trim21
2022 年 10 月 8 日
@windzzm 用 tsc $filename 指定文件名转译的时候 tsconfig.json 是无效的
windzzm
2022 年 10 月 8 日
@Trim21 原来如此,多谢
kkll7766
2022 年 11 月 22 日

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

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

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

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

© 2021 V2EX