Reputation: 85
state = {
x: Array<any>(),
y: number
}
y
gives me the following error:
only refers to a type but is being used as a value here.
which is understandable because it is object's property.
How can I use specify a type for this like the x
one?
Upvotes: 3
Views: 8792
Reputation: 250256
The problem is you are trying to assign to state
a type with the given structure. If you want to declare a variable or a field you need to use :
let state : {
x: Array<any>,
y: number
}
//Or for a field:
class Foo {
state: {
x: Array<any>,
y: number
}
}
If you want to create such an object you need to assign values, not types:
let state = { x: [], y: 0} // empty array for x
Upvotes: 2