Open jespertheend opened 2 years ago
Not really sure what is going on here, I'm trying create an object that is assignable to MessageHelper
with as minimal amount of casting as possible:
const message : MessageHelper<TMap, T> = {
bar: "bar",
type: type as keyof TMap,
};
But even casting to any
doesn't seem to work:
const message : MessageHelper<TMap, T> = {
bar: "bar",
type: type as any,
};
Only casting the entire message seems to get rid of the error, but this allows for making mistakes, for instance now you can omit bar
which might result in runtime errors later on:
const message : MessageHelper<TMap, T> = {
// bar: "bar",
type,
} as MessageHelper<TMap, T>;
The likely problem is that we're not using the correct cache (error-reporting vs non-error-reporting) somewhere in the stack. Likely an easy fix that's very difficult to find.
Bug Report
🔎 Search Terms
TS2322 unhelpful message
🕗 Version & Regression Information
TS2322
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The error that occurs when assigning
message
tomessage2
shows just🙂 Expected behavior
A better explanation of why the types are not assignable. I'm assuming it's because the types of
message.type
are different. But this isn't clearly shown in the error message.