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

Fix closure compiler error #572

Merged
merged 1 commit into from
Mar 12, 2024
Merged

Conversation

sjamesr
Copy link
Contributor

@sjamesr sjamesr commented Feb 29, 2024

I'm trying to fix some bugs in the Closure compiler template type checker. The fix has revealed a type error in shadydom, which this PR attempts to fix.

With the fix, the following error occurs:

shadydom/src/patch-events.js:286:53: ERROR - [JSC_TYPE_MISMATCH] actual parameter 3 of Object.defineProperty does not match formal parameter
found   : ObjectPropertyDescriptor<Event>
required: ObjectPropertyDescriptor<(Event|{
  composed: ?,
  composedPath: function(this:Event): ?,
  relatedTarget: ?,
  stopImmediatePropagation: function(this:Event): undefined,
  stopPropagation: function(this:Event): undefined,
  target: ?
})>
  286|     /** @type {!ObjectPropertyDescriptor<!Event>} */ ({
                                                            ^^
  287|       /**
       ^^^^^^^^^
...
  296|       configurable: true,
       ^^^^^^^^^^^^^^^^^^^^^^^^^
  297|     })
       ^^^^^^

This error is correct because EventPatches is an object literal, which can never be an Event because Event is a nominal type in Closure.

I think this change should be OK and will unblock Closure compiler fixes.

I'm trying to fix some bugs in the Closure compiler template type
checker. The fix has revealed a type error in shadydom, which this PR
attempts to fix.

With the fix, the following error occurs:

```
shadydom/src/patch-events.js:286:53: ERROR - [JSC_TYPE_MISMATCH] actual parameter 3 of Object.defineProperty does not match formal parameter
found   : ObjectPropertyDescriptor<Event>
required: ObjectPropertyDescriptor<(Event|{
  composed: ?,
  composedPath: function(this:Event): ?,
  relatedTarget: ?,
  stopImmediatePropagation: function(this:Event): undefined,
  stopPropagation: function(this:Event): undefined,
  target: ?
})>
  286|     /** @type {!ObjectPropertyDescriptor<!Event>} */ ({
                                                            ^^
  287|       /**
       ^^^^^^^^^
...
  296|       configurable: true,
       ^^^^^^^^^^^^^^^^^^^^^^^^^
  297|     })
       ^^^^^^

```

This error is correct because EventPatches is an object literal, which
can never be an Event because Event is a nominal type in Closure.

I think this change should be OK and will unblock Closure compiler
fixes.
@brad4d
Copy link

brad4d commented Mar 12, 2024

To clarify: In the description the phrase "with the fix the following error occurs" is saying that when closure-compiler is fixed it will report the error unless this PR is accepted first.

Please accept this PR to avoid having this error occur in your build.

@brad4d
Copy link

brad4d commented Mar 12, 2024

I think a better title for this issue would be "Fix a type error that closure-compiler misses now, but will soon start reporting"

@rictic rictic merged commit 651e207 into webcomponents:master Mar 12, 2024
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants