Microsoft/TypeScript

Misleading error message

Open

#56.230 aberto em 27 de out. de 2023

Ver no GitHub
 (2 comments) (0 reactions) (0 assignees)TypeScript (6.726 forks)batch import
Domain: Error MessagesHelp WantedPossible Improvement

Métricas do repositório

Stars
 (48.455 stars)
Métricas de merge de PR
 (Mesclagem média 6d 17h) (9 fundiu PRs em 30d)

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

Guia do colaborador