Open herrlegno opened 2 years ago
Also found another bug, but I don't know if it's React types or TypeScript Inference: Playground
Type 'Omit<T & { x: X; }, "x">' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'Omit<T & { x: X; }, "x">'.
That one had a workaround (and might be correct?), but it seems like there's a bug here.
T
is instantiated with an object that also has a property x
, the result of Omit<T & { x: X }, "x">
will not be assignable to T
.Likewise, the pattern in the OP here (and my reduced case) should be an error, since T
can be instantiated with an object including the legend
property (or foo
in my reduced case), but the elaboration in the error message is nonsensical:
Type 'Omit<Value & T & { foo: unknown; }, "foo">' is missing the following properties from type 'Value': key, color, value(2322)
This makes me think that it’s an error for a completely incorrect reason.
While I think something is definitely awry here, I’m going to bump it to the backlog since it shouldn’t compile and it doesn’t.
Never thought of the case where T could be instanciated with the same Omitted properties, that's correct. Nevertheless in that case the error should be something like #50604, so maybe is something else. Thank you for the clarification!
Also, could you take a look to the playground linked here?
Also found another bug, but I don't know if it's React types or TypeScript Inference: Playground
Should I make another issue in this repo or should I do it at React Types? I don't know who can be responsible of it. Thank you!
@herrlegno that’s a duplicate of #241 (congrats, you found a three-digit one!)
Bug Report
Typescript seems to not be able to infer correctly a rest object type.
I've found a workaround for it by nesting the value (in playground)
🔎 Search Terms
Destructuring
🕗 Version & Regression Information
Tested in 4.5.5, 4.8.2 and next (time of writing = v4.9.0-dev.20220908)
⏯ Playground Link
Playground
💻 Code
🙁 Actual behavior
Throws an error
🙂 Expected behavior
Expect to not throw an error as
Omit<Value & T & { legend: ... }, "legend" }> === Value & T