neefrehman / make-matrix Goto Github PK
View Code? Open in Web Editor NEWA simple, type-safe way to create multi-dimensional arrays
License: MIT License
A simple, type-safe way to create multi-dimensional arrays
License: MIT License
Currently this package uses overloads to safely type arrays of up to five dimensions, with a fallback generic return type, Matrix
, for less common cases, which is:
type Matrix<T> = T[][][][][] | Matrix<T>[];
The overload that returns this type is:
function makeMatrix<T>(
dimensions: number | number[],
initialValues?: T
): Matrix<T>;
This type will ensure a depth of at least 5 dimensions when used, but beyond that won't provide type-safety for individual points. I have a feeling that there's a better way to do this, and have been looking into recursive and keyof
types, but I'm struggling to get anywhere. Not even sure it's possible!
A fix for this would help ensure more type-safety across the board, and potentially allow me to not need overloads, as they currently bring their own UX problem where the first overload is suggested first, showing users that 1 | [number]
can be passed in as the dimensions
parameter, despite any number | number[]
being usable. Placing the generic overload first would solve this, but then wouldn't allow the more specific return types to then take over as they are all still a subset of number | number[]
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.