Open staab opened 1 month ago
I don't have the energy right now to minimize this Ramda madness further. This is what I got so far:
Amazing, I appreciate that. Ramda is madness, I'm planning to remove it from my project eventually. That gives me an action item, even if it doesn't help with resolving this issue for typescript.
We need a (reasonably small) repro
We just hit the same issue in our codebase (private). Can confirm the same versions: works fine in 5.5.4 but broken in 5.6. Bit tricky to provide a repro when there are no indication about where the error actually is.
Edit: also broken is @next (5.7.0-dev.20241104)
@RyanCavanaugh managed to reproduce it
import * as R from "ramda";
const mergeValue = { c: 3 };
const addCToFirstItem = R.adjust(0, R.mergeLeft(mergeValue));
// Should output [{ a: 1, c: 3 }, { b: 2 }]
console.log(addCToFirstItem([{ a: 1 }, { b: 2 }]));
Versions
@types/ramda: 0.30.2
ramda: 0.30.1
typescript: 5.6.3
Seems to be a combination of R.adjust and R.mergeLeft. Only happens when using --strict
.
We already have a Ramda-based repro, see even the rolled up one here. The problem is that their types are very complex - for somebody to investigate this issue it has to be reduced further
@Andarist @staab Hi, ramda/types maintainer here.
The code example given by @josh-cloudscape I don't think is the issue.
The code you used to reproduce the issue does run and produce the expected output
However, the error you are seeing here is valid from a type perspective: https://tsplay.dev/wjMv7W
The error is very difficult to decipher, and I do wish that was better, but what it's trying to tell you is since it doesn't know yet what the type R.adjust
is expecting it can't just merge { c: number }
into it.
Even if that wasn't the case you'd have a problem because [{ a: 1 }, { b: 2 }]
is infered as
({
a: number;
b?: undefined;
} | {
b: number;
a?: undefined;
})[]
And doesn't have a c
prop. So directly mutating would error: https://tsplay.dev/weqGgw
So the error isn't in Ramda, it's that your types are mismatched. Add some correct types and it works as expected: https://tsplay.dev/WGQLoN
The error around undefined length elaborateDidYouMeanToCallOrConstruct
is not directly from types-ramda
, but another project ts-toolbelt
R.mergeRight utilizes a type O.Assign from ts-toolbelt
ramda
existed long before typescript so a DefinitelyTyped project is where all the types were defined. ts-toolbelt
was originally added there. ramda
since pulled on those types int the types/ramda to allow us to accelerate typing improvements (and we've come a long way), but we can't just change from using ts-toolbelt
without breaking existing userspace. I do admit that ts-toolbelt
is very complex, but does simplify how we can type ramda functions in a sane way with expected behaviors in general.
Unfortunately, I cannot say why ts-toolbelt
is failing on typescript@5.6
🔎 Search Terms
undefined length elaborateDidYouMeanToCallOrConstruct
🕗 Version & Regression Information
npm i typescript@next
never completed, spamming the terminal with the following error for about 20 minutes before I killed it:⏯ Playground Link
No response
💻 Code
I'm not able to isolate the problem because the compiler is crashing without any information about my source files. You can clone the project from https://github.com/coracle-social/coracle and reproduce simply by running
git checkout 5e70d4ed499b6721f41318644b6250713085c923; npm i; npx tsc
.🙁 Actual behavior
Running
npx tsc
in my project gives me:On my Debian 11 VPS, I get a similar error:
🙂 Expected behavior
I expect typescript to not crash.
Additional information about the issue
I completely re-installed nvm/npm/node, removed all node_modules folders on my system, removed the project director and re-cloned, just to make sure my environment wasn't dirty somehow.