You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JS doesn't have a distinct int/Integer/int32 type but it would be really helpful and can prevent from many errors. Same for float/double/float32. In the same time JS has Int8Array/Uint8Array which is kind of imply existing of Int8/UInt8 but not directly declared.
I understand that the JsDoc here follows JS/EcmaScript/TypeScript spec but maybe it's possible to declare some number's "aliases" for int/float that will be fine syntactically.
In real life code base I saw a lot of @type {int} usages. This is due to IntelliJ IDE is fine with it and just threat it as a number. E.g. you can assign float numbers to an int field. I reported the problem.
The Idea is also fine with integer as a real type.
Here I tested a small sample of code:
classIntegerextendsNumber{}classUIntegerextendsNumber{}/** * @typedef {number} Int8 * @typedef {number} Int16 * @typedef {number} Int32 * @typedef {number} Int64 * @typedef {number} UInt8 * @typedef {number} UInt16 * @typedef {number} UInt32 * @typedef {number} UInt64 * @typedef {Int32} Int */classI{/** @type {Integer} */IdInteger/** @type {UInteger} */IdUInteger/** @type {Int} */IdInt/** @type {Int32} */Id16/** @type {int} */IdI}vars=newI()s.IdInteger=0// OK. IntelliJ is totally fine with this assignment if thes.IdInteger=null// OKs.IdUInteger=0// IntelliJ Warning: Assigned expression type number is not assignable to type UIntegers.IdInt=0// OKs.Id16=0// OKs.Id16=0.5// should be an error: float not alloweds.UId16=-0.5// should be an error: negative numbers.IdI=0s.IdI='0'// IntelliJ Warning: Assigned expression type string is not assignable to type ints.IdInteger=newInteger(42)// IntelliJ Warning: Method expression is not of Function type
If the both IntelliJ and JsDoc can add the layer of type check that may help to find many errors.
Similarly all kinds of int8/byte, int16/small, int64/long would be just great.
JS doesn't have a distinct int/Integer/int32 type but it would be really helpful and can prevent from many errors. Same for float/double/float32. In the same time JS has Int8Array/Uint8Array which is kind of imply existing of Int8/UInt8 but not directly declared.
I understand that the JsDoc here follows JS/EcmaScript/TypeScript spec but maybe it's possible to declare some
number
's "aliases" for int/float that will be fine syntactically.In real life code base I saw a lot of
@type {int}
usages. This is due to IntelliJ IDE is fine with it and just threat it as anumber
. E.g. you can assign float numbers to an int field. I reported the problem.The Idea is also fine with
integer
as a real type.Here I tested a small sample of code:
If the both IntelliJ and JsDoc can add the layer of type check that may help to find many errors.
Similarly all kinds of int8/byte, int16/small, int64/long would be just great.
Related:
The text was updated successfully, but these errors were encountered: