mhkeller / layercake

graphics framework for sveltejs
https://layercake.graphics
MIT License
1.41k stars 31 forks source link

Fix TypeScript errors in lib/utils #231

Open rgieseke opened 2 months ago

rgieseke commented 2 months ago

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);
mhkeller commented 1 month ago

Thanks for this one. I was away for a few weeks and will go through this.

mhkeller commented 1 month ago

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.