Skip to content

Commit 1e1c16d

Browse files
authored
Merge pull request #8 from neefrehman/features/matrix_types
features/matrix types
2 parents 65b0d82 + bc4cd96 commit 1e1c16d

20 files changed

+46446
-15511
lines changed

.eslintrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"plugins": ["@typescript-eslint", "prettier"],
1313
"extends": [
1414
"plugin:@typescript-eslint/recommended",
15-
"prettier",
16-
"prettier/@typescript-eslint"
15+
"prettier"
1716
],
1817
"rules": {
1918
"strict": 0,
@@ -26,6 +25,7 @@
2625
}
2726
}
2827
],
29-
"prettier/prettier": "warn"
28+
"prettier/prettier": "warn",
29+
"@typescript-eslint/ban-ts-comment": "off"
3030
}
3131
}

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"printWidth": 82,
2+
"printWidth": 92,
33
"tabWidth": 4,
44
"singleQuote": false,
55
"trailingComma": "none",

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsdk": "node_modules/typescript/lib"
3+
}

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ const twoDRandomNumberArray = makeMatrix([7, 3, 8], (vector) => {
9696

9797
This package comes with type definitions to provide type-safety when working with the returned arrays.
9898

99-
Up to and including four dimensions, returned arrays will be given a specific type dictated by `T` and the number of dimensions, where `T` is the type of the value passed to the functions `initialValues` parameter (or `unknown` if not set).
99+
Returned Matrices will be given a specific type dictated by `T` and the number of dimensions, where `T` is the type of the value passed to the functions `initialValues` parameter (or `unknown`, if not set).
100100

101-
For example, a three-dimensional array of numbers will be of type `number[][][]`. Points within the matrix can then only be reassigned to numbers. TypeScript's compiler will present errors when any reassignments are of the wrong type, including if they are at an incorrect depth in the array. This type-safety also exists when callbacks are used to dynamically populate your matrix.
101+
For example, a three-dimensional array of numbers will be of type `number[][][]`. Points within the matrix can then only be reassigned to numbers. TypeScript's compiler will present errors when any reassignments are of the wrong type, including if they are at an incorrect depth in the array. This type-safety also occurs when callbacks are used to dynamically populate your matrix.
102102

103103
```ts
104104
const threeDNumberArray = makeMatrix([2, 6, 5], 0); // return type of number[][][]
@@ -112,13 +112,7 @@ threeDNumberArray[2][1] = 10; // error: Type '"value"' is not assignable to type
112112
threeDNumberArray[2][1][2][0] = 10; // error: Property '0' does not exist on type 'Number'
113113
```
114114

115-
Above four dimensions, the returned array will have the generic type `Matrix<T>`. This type will ensure a minimum array depth of five levels, but won't be able to check the type of points within the matrix at six or more dimensions. The `Matrix` type is also a named export of this package, to be annotated manually if needed.
116-
117-
For more type-safety at these levels of dimensionality, it is recomended that you add more specific type annotations to your variables:
118-
119-
```ts
120-
const sixDimensionalNumberArray: string[][][][][][] = makeMatrix(6, "this is deep");
121-
```
115+
This type-safety will work for any number of dimensions, however large numbers may slow down your typescript server, due to the nature of the recursive types working under the hood.
122116

123117
## Example
124118

0 commit comments

Comments
 (0)