Skip to content

Misleading error elaboration #25971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ahejlsberg opened this issue Jul 26, 2018 · 1 comment
Closed

Misleading error elaboration #25971

ahejlsberg opened this issue Jul 26, 2018 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Fixed A PR has been merged for this issue

Comments

@ahejlsberg
Copy link
Member

TypeScript Version: 3.1.0-dev

Search Terms: Error elaboration

Code

function foo<T extends { a: string }>(x: T) {
    x = { a: "abc", b: 20, c: 30 };
}

Expected behavior: An error stating { a: string, b: number, c: number } is not assignable to T.

Actual behavior: Elaboration errors on the b and c property assignments which misleads the user to think the issue is with those properties. The real issue is that no object literal and only a T is assignable to T, and we should not attempt to elaborate here. Generally, the elaboration logic can't rely on the behavior of getIndexedAccess without first validating that a meaningful type is being requested because getIndexedAccess will happily create deferred indexed access types that technically are errors. The elaboration logic needs to be more selective about which target types it descends into. Specifically, I would suggest only descending into non-generic object types and non-generic intersection types.

@ahejlsberg ahejlsberg added the Bug A bug in TypeScript label Jul 26, 2018
@ahejlsberg
Copy link
Member Author

Additionally, since I didn't get to review #25140, please remove the generator functions and just use normal recursive descent. There's no need for generators here and it is inconsistent with what we do elsewhere (such as the conceptually similar logic to relate types and compute contextual types).

@mhegazy mhegazy added this to the TypeScript 3.1 milestone Jul 26, 2018
@DanielRosenwasser DanielRosenwasser added the Domain: Error Messages The issue relates to error messaging label Oct 30, 2018
@DanielRosenwasser DanielRosenwasser added the Fixed A PR has been merged for this issue label Nov 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

5 participants