Coder Social home page Coder Social logo

neefrehman / make-matrix Goto Github PK

View Code? Open in Web Editor NEW
24.0 24.0 1.0 15.6 MB

A simple, type-safe way to create multi-dimensional arrays

License: MIT License

TypeScript 100.00%
array generator graphics javascript math matrices matrix multidimensional-arrays typescript webgl

make-matrix's Introduction

make-matrix's People

Contributors

dependabot[bot] avatar neefrehman avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

odnodn

make-matrix's Issues

Better type-safety for 6+ dimensions

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[].

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.