diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index 316e631b9d..9e6a67e440 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -1368,7 +1368,7 @@ interface JQuery { * @see {@link https://api.jquery.com/offset/} * @since 1.2 */ - offset(): JQuery.Coordinates; + offset(): JQuery.Coordinates | undefined; /** * Get the closest ancestor element that is positioned. * diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index 376eaa51f6..e2cea8ba54 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -601,7 +601,7 @@ function JQuery() { }; }); - // $ExpectType Coordinates + // $ExpectType Coordinates | undefined $('p').offset(); } diff --git a/types/jquery/test/example-tests.ts b/types/jquery/test/example-tests.ts index f59f8a3acc..0c871de0a7 100644 --- a/types/jquery/test/example-tests.ts +++ b/types/jquery/test/example-tests.ts @@ -3754,13 +3754,13 @@ function examples() { function offset_0() { var p = $('p:last'); - var offset = p.offset(); + var offset = p.offset()!; p.html('left: ' + offset.left + ', top: ' + offset.top); } function offset_1() { $('*', document.body).click(function(event) { - var offset = $(this).offset(); + var offset = $(this).offset()!; event.stopPropagation(); $('#result').text(this.tagName + ' coords ( ' + offset.left + ', ' + offset.top + ' )');