microsoft / microsoft/TypeScript
Misleading error message
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the assignment diagnostic in the linked TypeScript Playground using the provided code, then trace how the incompatibility message is selected for the item and fields members. Done means the diagnostic identifies fields as the problematic member and the relevant regression coverage passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100