-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
数组的类型 #157
Comments
上一节不是说:一旦定义了任意属性,那么确定属性和可选属性的类型都必须是它的类型的子集。那为什么 |
是不是因为严格模式下没有callee所以不报错呢? |
有一个前提,任意属性的类型为string时,那么确定属性和可选属性的类型都必须为它的类型的子集,这个例子是number类型,所以没有报错,你把任意属性类型换成string就会 |
我试了下是报错对的。但是发现用webstorm的自动编译js,编辑器未报错。如果直接用tsc命令手动编译js则报错。应该对的,以tsc命令为准 |
type Arg = {
[index: number]: string
length: number
} 如上,虽然指定了 但是反过来就不一样了,如果接口定义了 |
3楼正解.. index是number类型, 不会检测其他非number类型的key |
function sum() { |
正解 |
官方文档 太生涩了 |
如下, 这样也是不会报错的, 是什么原因呢 |
https://ts.xcatliu.com/basics/type-of-array.html
The text was updated successfully, but these errors were encountered: