snippettypescriptCritical
How do you specify that a class property is an integer?
Viewed 0 times
propertyyouhowclassintegerspecifythat
Problem
I'm experimenting with
First off, in Visual Studio 2012 with the TypeScript plugin, I see
the name 'int' does not exist in the current scope.
I reviewed the language specs and see only the following primitive types:
So, I'm left with two questions:
-
How should I indicate to users of my class that a particular field is not just a
-
Why do I see
Update: All the answers I've gotten so far are about how
TypeScript, and in the process of creating a class with an ID field that should be an integer, I have gotten a little confused.First off, in Visual Studio 2012 with the TypeScript plugin, I see
int in the intelliSense list of types. But I get a compile error that says:the name 'int' does not exist in the current scope.
I reviewed the language specs and see only the following primitive types:
number, string, boolean, null, and undefined. No integer type.So, I'm left with two questions:
-
How should I indicate to users of my class that a particular field is not just a
number but an integer (and never a floating point or decimal number)?-
Why do I see
int in the intellisense list if it's not a valid type?Update: All the answers I've gotten so far are about how
JavaScript doesn't have an int type, it would be hard to enforce an int type at runtime... I know all that. I am asking if there is a TypeScript way to provide an annotation to users of my class that this field should be an integer. Perhaps a comment of some particular format?Solution
-
I think there is not a direct way to specify whether a number is integer or floating point. In the TypeScript specification section 3.2.1 we can see:
"...The Number primitive type corresponds to the similarly named JavaScript primitive type and represents double-precision 64-bit format IEEE 754 floating point values..."
-
I think
I think there is not a direct way to specify whether a number is integer or floating point. In the TypeScript specification section 3.2.1 we can see:
"...The Number primitive type corresponds to the similarly named JavaScript primitive type and represents double-precision 64-bit format IEEE 754 floating point values..."
-
I think
int is a bug in Visual Studio intelliSense. The correct is number.Context
Stack Overflow Q#12897742, score: 196
Revisions (0)
No revisions yet.