GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix Array.prototype.includes not finding NaN by bardrop · Pull Request #1737 · TypeScriptToLua/TypeScriptToLua

Conversation

@bardrop

@bardrop bardrop commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #1735

Array.prototype.includes uses SameValueZero, so [1, NaN, 3].includes(NaN) is true in JS. __TS__ArrayIncludes compared each element with ==, and NaN == NaN is always false in Lua, so it returned false.

The lualib now checks once whether the search value is NaN (searchElement !== searchElement, same trick as __TS__NumberIsNaN) and, if so, also matches an element that is not equal to itself. For any other search value the loop does the same == check as before. The generated Lua stays a plain loop:

local searchingForNaN = searchElement ~= searchElement
for i = k + 1, len do
    local element = self[i]
    if element == searchElement or searchingForNaN and element ~= element then
        return true
    end
end

Tests: added [1, NaN, 3].includes(NaN) (fails before, passes after) and [1, 2, 3].includes(NaN) to the array.includes cases in test/unit/builtins/array.spec.ts. npm run lint and the full jest run pass.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bardrop
fix Array.prototype.includes not finding NaN
f2cffde
includes uses SameValueZero, so [NaN].includes(NaN) is true.
The lualib compared with ==, which is always false for NaN in Lua.

Fixes TypeScriptToLua#1735
@Perryvw
Perryvw merged commit 78baaab into TypeScriptToLua:master Nov 12, 2026
5 checks passed

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Array.prototype.includes returns false for NaN

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@bardrop @Perryvw
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.