Skip to content

Conversation

@DanielRosenwasser
Copy link
Member

Everyone is trying to fix #51521, so I guess I am too.

This PR tries to fix #51521. It does so by fixing setValueDeclaration to defer to property declarations over "assignment declarations" - even in the case of ambients. In the case of code like in the following .js file:

class C {
  constructor() {
    this.foo = 10;
  }
  declare foo: number;
}

We'll encounter the this.foo = 10 assignment first, then encounter declare foo: number;.

Even though declare foo: number is marked as ambient, it is arguably a better value declaration than the JavaScript one.

Semantic Diagnostics for file '/tests/cases/fourslash/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.ts':


==== /test.js (0 errors) ====
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait. This is wrong.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that the errors don't come up consistently, and that baselining doesn't give the same error results, is very suspicious.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. All tests I've had for this have not been compiler tests.

@DanielRosenwasser DanielRosenwasser changed the title Fix issue with Fix issue with ambient property declaration following property assignment in JS Jan 20, 2023
@Andarist
Copy link
Contributor

Andarist commented Jan 20, 2023

Everyone is trying to fix #51521, so I guess I am too.

And now I have FOMO...

@DanielRosenwasser
Copy link
Member Author

I am sure you can find something that looks broken with our JavaScript support.

@DanielRosenwasser
Copy link
Member Author

Looks like @a-tarasyuk's PR makes a fix in the same place.

@DanielRosenwasser DanielRosenwasser deleted the fixDebugAssert51521 branch January 20, 2023 17:28
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using a of property declared after an initializing constructor triggers an assertion failure in JS

4 participants