0
type InputValue: number;

function(value: InputValue) {
   // do something here
}

There is not int number in Typescript (only BigInt)

How to enforce value has 0 decimal digit (i.e. it's not a float number) as a type without additional logic / type assertions?

dragonmnl
  • 14,578
  • 33
  • 84
  • 129
  • I don't think this is currently possible in TypeScript specification. You can find better answers [here](https://stackoverflow.com/questions/12897742/how-do-you-specify-that-a-class-property-is-an-integer) – Lykos94 Aug 16 '20 at 22:14
  • You cannot enforce that via the type system, only via code. – Nicholas Tower Aug 16 '20 at 22:14
  • Does this answer your question? [How do you specify that a class property is an integer?](https://stackoverflow.com/questions/12897742/how-do-you-specify-that-a-class-property-is-an-integer) – Rob Napier Aug 16 '20 at 22:20
  • I guess the answer is no then. how can I close the question on my own? – dragonmnl Aug 16 '20 at 22:26
  • @dragonmnl, You should watch https://github.com/microsoft/TypeScript/pull/39784 for this feature (since this may add `i32/64` support to TypeScript) – Elias Schablowski Aug 17 '20 at 04:40

1 Answers1

2

How to enforce value has 0 decimal digit (i.e. it's not a float number) as a type without additional logic / type assertions?

TypeScript does not support an int data type.

Why

Because JavaScript doesn't support it. TypeScript is just JavaScript with type annotations.

basarat
  • 261,912
  • 58
  • 460
  • 511