Microsoft/TypeScript

Misleading error message

Open

#56 230 ouverte le 27 oct. 2023

Voir sur GitHub
 (2 commentaires) (0 réactions) (0 assignés)TypeScript (6 726 forks)batch import
Domain: Error MessagesHelp WantedPossible Improvement

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (9 PRs mergées en 30 j)

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

https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgPIAczAPYgDwAqAfMgN4CwAUMjcsJALYD8AXMgQNxW3IzAQAbACYBnVsgAUAawgBPbDHYBKDgHpVyAK4jQAc2QADEWCh6A2gF0DyOCORhZ6FAAtoKAO7ZNw5AzgzkdGwRHQAjARQwV3swMBsQ4F0QBghwKgBfKgQBWzsCCGMAIVsIQmQIAA9IEFFkbFCAKwgEOIBeOsbmsBIKalpIYwkwNgwsXEIiJTJMyhnQSFhEFAARODA4Mm5aITW4NmNTEF0uWayckPYCsABhZ2AfSura-KKSvFX1nq2aAbAhkcwOHwHzgk2mGSoVAicViw0urxEKHaIAg7nhNzuwgkKiAA

💻 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

Guide contributeur