Closed axelboc closed 3 weeks ago
TypeScript 5.2
* [Easier Method Usage for Unions of Arrays](https://devblogs.microsoft.com/typescript/announcing-typescript-5-2/#easier-method-usage-for-unions-of-arrays) - we can finally loop through arrays of type `number[] | TypedArray` with `filter`, `map`, etc. but now that I'm looking through the code, I can no longer recall a specific case where we had to work around this limitation... 🤷♀️
IIRC, it was for the bounds computation: https://github.com/silx-kit/h5web/blob/86848a7fe2fd9e11563276c3ddc41eae764711e6/packages/shared/src/vis-utils.ts#L128
IIRC, it was for the bounds computation:
Ooh nice! :fishing_pole_and_fish:
Arf no luck, seems to work only with unions of plain arrays, like number[] | string[]
, not with unions of typed and plain arrays like in the case of the NumArray
type in getBounds
. :cry:
I found an old stash from a past attempt at upgrading TypeScript from 5.0 to 5.2. Turns out I missed this refactoring opportunity when I looked at it again in #1636.
I had also taken some notes of interesting changes in 5.1 and 5.2 in case this is of interest:
Typescript 5.1
return
statement is still required for all code paths, and it feels weird havingreturn;
at the end of a function; I much prefer the explicitness ofreturn undefined;
. Might help simplify other cases that I'm not seeing. 🤷♀️return <>{children}</>
! 🎉TypeScript 5.2
number[] | TypedArray
~number[] | string[]
withfilter
,map
, etc. but now that I'm looking through the code, I can no longer recall a specific case where we had to work around this limitation... EDIT: we encountered this ingetBounds
withNumArray
, a union of plain and typed arrays, which isn't covered here.arr.toReversed()
,arr.toSorted()
, etc. are now supported by TS ... but they still need to be polyfilled for older browsers, so not worth using yet.