for-in 语句 [英] for-in statement

查看:22
本文介绍了for-in 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TypeScript 文档没有提到像 forfor-in 这样的循环.从使用语言来看,for 循环似乎只支持 anystring 变量.

TypeScript docs say nothing about loop like for or for-in. From playing with the language it seems that only any or string variables are supported in for loop.

为什么做出这个决定?

为什么不使用类型信息并具有强类型迭代变量?

Why not use the type information and have strongly-typed iteration variable?

推荐答案

for-in 语句确实用于枚举对象属性,这就是它在 TypeScript 中的实现方式.在数组上使用它存在一些问题.

The for-in statement is really there to enumerate over object properties, which is how it is implemented in TypeScript. There are some issues with using it on arrays.

我不能代表 TypeScript 团队发言,但我相信这是在语言中实现的原因.

I can't speak on behalf of the TypeScript team, but I believe this is the reason for the implementation in the language.

这篇关于for-in 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆