Skip to content
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

Duplicate diagnostics #58207

Closed
gabritto opened this issue Apr 15, 2024 · 2 comments Β· Fixed by #58220 or #58318
Closed

Duplicate diagnostics #58207

gabritto opened this issue Apr 15, 2024 · 2 comments Β· Fixed by #58220 or #58318
Assignees
Labels
Bug A bug in TypeScript

Comments

@gabritto
Copy link
Member

πŸ”Ž Search Terms

duplicate diagnostics, duplicate errors

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.5.0-dev.20240415#code/JYOwLgpgTgZghgYwgAgMIHsC2AHANsBOSAEwBUBPbCAITgGcUBvAKGTeQG06AuZOsKKADmAXV4BBWgwDczAL7NQkWIhQYc+QiQpUAItGAA3CMWQt2nHnwHCxycfsHHishUujwk9qU1bs4vPyCIEKuiuAeqvaORiZmfmwARoE2IWEIuPR0yD7xFjDo6ACEvOp4BEQmOjT0EOnoIPzIAB7IALzIGVnIMc7IEM2QIMTZuebsBcWlWOVaVZQQvSZhuBBgyOiJAFa8jMgAzCnBQshy7WYHvABEYAAWUBAQV6eym1sczSLSQA

πŸ’» Code

interface ComplicatedTypeBase {
    [s: string]: ABase;
}
interface ComplicatedTypeDerived {
    [s: string]: ADerived;
}
interface ABase {
    a: string;
}
interface ADerived {
    b: string;
}
class Base {
    foo!: ComplicatedTypeBase;
}
const x = class Derived extends Base {
    foo!: ComplicatedTypeDerived;
}
let obj: { 3: string } = { 3: "three" };
obj[x];

πŸ™ Actual behavior

Two instances of the same error on line foo!: ComplicatedTypeDerived;:

  • Property 'foo' in type 'Derived' is not assignable to the same property in base type 'Base'. Type 'ComplicatedTypeDerived' is not assignable to type 'ComplicatedTypeBase'.(2416)
  • Property 'foo' in type 'Derived' is not assignable to the same property in base type 'Base'. Type 'ComplicatedTypeDerived' is not assignable to type 'ComplicatedTypeBase'. 'string' index signatures are incompatible. Property 'a' is missing in type 'ADerived' but required in type 'ABase'.(2416)

πŸ™‚ Expected behavior

A single instance of the error

Additional information about the issue

No response

@gabritto
Copy link
Member Author

Found this when coming up with test cases for #57842.
The way I came up with it is to look at where we call getTypeOfExpression, and then create a program where we call getTypeOfExpression on an expression that produces an error that is dependent on the state of the checker, such that we end up with two different diagnostics, one when we check the expression regularly, another when we re-check the expression through a call to getTypeOfExpression.

Note this is not unique to checking class expressions, nor to the specific error code in the example: I can likely construct other types of program that exhibit this same problem.

@ahejlsberg
Copy link
Member

I think our duplicate elimination machinery needs to be smarter about removing error messages without elaborations when otherwise identical error messages with elaborations exist for the same location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
3 participants