Skip to content

Conversation

@neefrehman
Copy link
Owner

This is a breaking change to how the library handles cases where a primitive instead of a literal type is used for the number of dimensions. Previously, the resulting Matrix would resolve to any[], as the complier is unable to infer how it should be typed (other than that it must be an array). This allowed to compiler to avoid throwing a type instantiation is excessively deep error, but also introduced an any into the user's codebase, which is less than ideal.

Now, the library will return a type of unknown[] in these cases. This achieves the same basic amount of type safety, but also means that users will not be able to use the resulting matrix in as many places as any[] would have allowed. The resulting matrix must now be typed by the caller. If you are able to provide more information than the compiler can infer. If not, then an explicit return type of any[] will provide the most 'relaxed' typing experience.

const createDynamicMatrix = (dimensions: number[]) => makeMatrix(dimensions, 0); // now typed as unknown[]

@neefrehman neefrehman merged commit aaaae72 into main Nov 19, 2023
@neefrehman neefrehman deleted the change-any-to-unknown-for-dynamic-matrix branch November 19, 2023 12:47
github-actions bot pushed a commit that referenced this pull request Nov 19, 2023
## [3.0.3](v3.0.2...v3.0.3) (2023-11-19)

### Bug Fixes

* **types:** change `any[]` to `unknown[]`, if creating a matrix of dy… ([#21](#21)) ([aaaae72](aaaae72))
@github-actions
Copy link

🎉 This PR is included in version 3.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant