diff --git a/src/core/function/typed.js b/src/core/function/typed.js index a3f9c90d6d..037345cfc8 100644 --- a/src/core/function/typed.js +++ b/src/core/function/typed.js @@ -361,6 +361,25 @@ export const createTyped = /* #__PURE__ */ factory('typed', dependencies, functi throw usualError } + // Provide a suggestion on how to call a function elementwise + // This was added primarily as guidance for the v10 -> v11 transition, + // and could potentially be removed in the future if it no longer seems + // to be helpful. + typed.onMismatch = (name, args, signatures) => { + const usualError = typed.createError(name, args, signatures) + if (['wrongType', 'mismatch'].includes(usualError.data.category) && + args.length === 1 && isCollection(args[0]) && + // check if the function can be unary: + signatures.some(sig => !sig.params.includes(','))) { + const err = new TypeError( + `Function '${name}' doesn't apply to matrices. To call it ` + + `elementwise on a matrix 'M', try 'map(M, ${name})'.`) + err.data = usualError.data + throw err + } + throw usualError + } + return typed }) diff --git a/types/index.d.ts b/types/index.d.ts index 713f8b0fb0..262af7d5d8 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -978,7 +978,7 @@ declare namespace math { cbrt(x: number, allRoots?: boolean): number cbrt(x: BigNumber): BigNumber cbrt(x: Complex, allRoots?: boolean): Complex - cbrt(x: Unit, allRoots?: boolean): Unit + cbrt(x: Unit): Unit // Rounding functions, grouped for similarity, even though it breaks // the alphabetic order among arithmetic functions.