Fix TypeScript errors in lib/utils
This fixes a few more TypeScript errors, those in lib/utils (see #218).
The error messages were:
src/lib/utils/makeAccessor.js:4:33
Error: Generic type 'Array<T>' requires 1 type argument(s).
Make an accessor from a string, number, function or an array of the combination of any
@param {string|number|Function|Array} acc The accessor function, key or list of them.
@returns {Function} An accessor function.
--
src/lib/utils/makeAccessor.js:8:23
Error: Type 'null' is not assignable to type 'Function'.
export default function makeAccessor(acc) {
if (!canBeZero(acc)) return null;
if (Array.isArray(acc)) {
--
src/lib/utils/makeAccessor.js:10:10
Error: Parameter 'd' implicitly has an 'any' type.
if (Array.isArray(acc)) {
return d =>
acc.map(k => {
--
src/lib/utils/makeAccessor.js:15:10
Error: Parameter 'd' implicitly has an 'any' type.
} else if (typeof acc !== 'function') {
return d => d[acc];
}
--
src/lib/utils/filterObject.js:10:34
Error: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
No index signature with a parameter of type 'string' was found on type '{}'.
Object.entries(obj).filter(([key, value]) => {
return value !== undefined && comparisonObj[key] === undefined;
--
src/lib/utils/debounce.js:8:6
Error: Variable 'timer' implicitly has type 'any' in some locations where its type cannot be determined.
export default function debounce(func, timeout = 300) {
let timer;
return (...args) => {
--
src/lib/utils/debounce.js:9:10
Error: Rest parameter 'args' implicitly has an 'any[]' type.
let timer;
return (...args) => {
clearTimeout(timer);
--
src/lib/utils/debounce.js:10:16
Error: Variable 'timer' implicitly has an 'any' type.
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => {
--
src/lib/utils/debounce.js:12:15
Error: 'this' implicitly has type 'any' because it does not have a type annotation.
timer = setTimeout(() => {
func.apply(this, args);
}, timeout);
--
src/lib/utils/arraysEqual.js:6:10
Error: Generic type 'Array<T>' requires 1 type argument(s).
of making a set
@param {Array} arr1 An array to test
@param {Array} arr2 An array to test against
--
src/lib/utils/arraysEqual.js:7:10
Error: Generic type 'Array<T>' requires 1 type argument(s).
@param {Array} arr1 An array to test
@param {Array} arr2 An array to test against
@returns {boolean} Whether they contain all and only the same items
--
src/lib/utils/padScale.js:19:34
Error: Parameter 'scale' implicitly has an 'any' type.
export default function padScale(scale, padding) {
if (typeof scale.range !== 'function') {
--
src/lib/utils/padScale.js:19:41
Error: Parameter 'padding' implicitly has an 'any' type.
export default function padScale(scale, padding) {
if (typeof scale.range !== 'function') {
--
src/lib/utils/padScale.js:41:38
Error: Parameter 'd' implicitly has an 'any' type.
const [d1, d2] = scale.domain().map(d => {
return isTime ? lift(d.getTime()) : lift(d);
Thanks for this one. I was away for a few weeks and will go through this.
I think this is looking really good. I made some changes and added some comments. I still need to go through makeAccessor. It may be an improvement to define the Function more.
I hadn't had a chance to work on Layer Cake projects for a while, but now I was working on one and am motivated to finish this!
Happy to simplify this into multiple PRs, if there is some stuff that still needs more thinking and sorry for the long delay!
I think keeping it in one PR is okay. I think I needed to still go through some of the files, too. I've been spending a lot of time on a layercake-adjacent project but the positive part of that is I have been using types a lot more. I appreciate your help in working on this more!
This ended up being a big merge. I also did things in the lib folder. I'm going to merge it for now before it gets any bigger.