thi-ng / umbrella

⛱ Broadly scoped ecosystem & mono-repository of 199 TypeScript projects (and ~180 examples) for general purpose, functional, data driven development
https://thi.ng
Apache License 2.0
3.41k stars 151 forks source link

[math] Documentation is misleading for function parameters #409

Open jffaust opened 1 year ago

jffaust commented 1 year ago

I was looking to use the fit function from the math package. I looked at the documentation to understand how to use it.

image

The parameters of the function in the documentation are: a, b, c, d, e

And the documentation states that "Returns a number in the [c,d] interval which is relative to x in the [a,b] interval". I found it a bit weird that it specified the x parameter but all the others were valid so I thought the e parameter must be x.

I was getting really weird behavior in my code so I looked up the code of the function and x is actually the first parameter :O

This must be because of the Fn5 type used under the hood.

Taking a closer look at the help in my editor, I can see the the first parameter is x (@param x) but it's still quite confusing and impossible to know from the documentation site:

image

postspectacular commented 1 year ago

This is really an (unresolved) issue with arrow functions, predeclared function types and how they're handled by TypeDoc and/or the TypeScript language server in general (tl;dr like 3rd class citizens). Also see #385 and #362 for related aspects... The only way around this seems to be a) replacing all arrow function with "normal" functions or b) removing the usage of function types and adding type info to each arg. Both are non-desirable/non-beneficial changes. My recommendation is to file some related issues with either TypeDoc and/or TypeScript... I personally don't have the bandwidth to deal with this, but would be grateful to anyone who does...