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
Currently the array types like Coordinate, Size, Extent are defined as Array<number>. This works for plain Javascript and for Typescript when the noUncheckedIndexedAccess compiler flag is disabled (default).
However, if extra type safety is wanted and the flag is enabled, those types become difficult to use. Typescript can't tell how many values a number array contains, so all extracted values will be number | undefined.
Would it be possible for Openlayers to define these types as tuples instead?
Extent would be [number, number, number, number]
Size would be [number, number]
Coordinate would probably have to be [number, number] | [number, number, number] | [number, number, number, number]
typeCurrentCoordinate=number[];typeBetterCoordinate=[number,number]|[number,number,number]|[number,number,number,number];constcurrentCoordinate=[1,2]asCurrentCoordinate;constbetterCoordinate=[1,2]asBetterCoordinate;constbetterXyzCoordinate=[1,2,3]asBetterCoordinate;// Error: object is possibly 'undefined' :(constfoo=currentCoordinate[0]+1;// Just works :)constbar=betterCoordinate[0]+1;// Any coordinate is guaranteed to have at least the X and Y// x = number// y = number// z = number | undefined// m = number | undefinedconst[x,y,z,m]=betterXyzCoordinate;
The text was updated successfully, but these errors were encountered:
Currently the array types like
Coordinate
,Size
,Extent
are defined asArray<number>
. This works for plain Javascript and for Typescript when the noUncheckedIndexedAccess compiler flag is disabled (default).However, if extra type safety is wanted and the flag is enabled, those types become difficult to use. Typescript can't tell how many values a number array contains, so all extracted values will be
number | undefined
.Would it be possible for Openlayers to define these types as tuples instead?
Extent
would be[number, number, number, number]
Size
would be[number, number]
Coordinate
would probably have to be[number, number] | [number, number, number] | [number, number, number, number]
Example:
The text was updated successfully, but these errors were encountered: