I'm experimenting with 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 aninteger
(and never afloating
point ordecimal
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?