我的意思是写一个类型的参数number,但我错误拼写了类型,Number而是写作.
在我的IDE(JetBrains WebStorm)上,类型Number使用与原始类型相同的颜色编写number,而如果我写了一个类的名称(已知或未知),它使用不同的颜色,所以我猜它以某种方式识别它拼写错误的类型作为正确/几乎正确/排序正确的类型.
当我编译代码时,而不是抱怨例如编译器找不到名为的类Number,TSC写入此错误消息:
Illegal property access
Run Code Online (Sandbox Code Playgroud)
这是否意味着number并且Number两者共存为不同的类型?
如果这是真的,这些类之间的区别是什么?
如果不是这种情况,那么为什么它只是没有写出它为未知类显示的相同错误消息("当前范围中不存在名称'数字'")
这是代码:
class Test
{
private myArray:string[] = ["Jack", "Jill", "John", "Joe", "Jeff"];
// THIS WORKS
public getValue(index:number):string
{
return this.myArray[index];
}
// THIS DOESN'T WORK: ILLEGAL PROPERTY ACCESS
public getAnotherValue(index:Number):string
{
return this.myArray[index];
}
}
Run Code Online (Sandbox Code Playgroud)