倉庫指標
- Star
- (48,455 star)
- PR 合併指標
- (平均合併 6天 17小時) (30 天內合併 9 個 PR)
描述
🔎 Search Terms
Misleading error message
🕗 Version & Regression Information
I think in all version but I just tries 5.2.2 and 5.3.0-beta
⏯ Playground Link
💻 Code
interface Option<T> {
item?: T;
fields?: (keyof T);// using `string[]` as type here would make possible the ttt assignment
}
class TestBase<T extends object = object> {
test(t: Option<T>) {}
}
interface Data {
data: string;
}
class TestChild extends TestBase<Data> {
test(t: Option<Data>) {}
}
let ttt: TestBase = new TestChild();
🙁 Actual behavior
In the error message if I hover over ttt it states that the item member is incompatible, but I think it is not the problem but the fields member. If I change its type from (keyof T)[] to type string[] the error is solved but as I see this means the error message was misleading.
🙂 Expected behavior
The error message should state that the fields member is the problematic
Additional information about the issue
I think the problem is that fields member has type keyof object in base class (TestBase) which maybe results in type never and in derivative class (TestChild) the fields results in "data" which is defineatly not assignable to never type.
Although I have years of experience in ts it can surprise me sometimes. :)
ps: Sorry if it is a known issue or expected behavior. Then please point me out to the corresponding documentation