Skip to content

Commit

Permalink
Fix closure compiler error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sjamesr committed Feb 29, 2024
1 parent f91938f commit 3d27b4e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/shadydom/src/patch-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,14 @@ if (eventPhaseDescriptor) {
Object.defineProperty(
EventPatches,
'eventPhase',
/** @type {!ObjectPropertyDescriptor<!Event>} */ ({
/** @type {!ObjectPropertyDescriptor<!{
composed: ?,
composedPath: function(this:Event): ?,
relatedTarget: ?,
stopImmediatePropagation: function(this:Event): undefined,
stopPropagation: function(this:Event): undefined,
target: ?
}>} */ ({
/**
* @this {Event}
*/
Expand Down

0 comments on commit 3d27b4e

Please sign in to comment.