Sometimes, we want to specify that a class property is an integer with TypeScript.
In this article, we’ll look at how to specify that a class property is an integer with TypeScript.
How to specify that a class property is an integer with TypeScript?
To specify that a class property is an integer with TypeScript, we can use the number type.
For instance, we write
class C {
public myInt: number;
}
to declare the myInt class property with type number`.
We can set myInt to any number, but we can add checks to check that the number is an integer.
Conclusion
To specify that a class property is an integer with TypeScript, we can use the number type.