声明多个具有相同类型的 TypeScript 变量 [英] Declaring multiple TypeScript variables with the same type

查看:44
本文介绍了声明多个具有相同类型的 TypeScript 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个大型 TypeScript 类,并将 noImplicitAny 设置为 true.有没有办法在同一行声明多个相同类型的变量?

I'm coding a large TypeScript class and I've set noImplicitAny to true. Is there any way to declare multiple variables of the same type on the same line?

我想将 x 和 y 声明为带有x, y: number"之类的数字.但是编译器不喜欢那个或我尝试过的任何其他东西.有没有比x: number"更好的选择?y:数字"?

I'd like to declare x and y as numbers with something like "x, y: number". But the compiler doesn't like that or anything else I've tried. Is there a better alternative to "x: number; y: number"?

推荐答案

没有任何语法能比两次编写类型更好地实现这一点.

There isn't any syntax that would accomplish this in a better way than just writing the type twice.

这篇关于声明多个具有相同类型的 TypeScript 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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