Skip to content

Property 'difference' does not exist on type 'Set' #60012

Description

🔎 Search Terms

is:issue set difference does not exist

🕗 Version & Regression Information

I tested this on the Nightly TypeScript version, 5.7, 5.6, etc.

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about FAQ (For Issue Filers)

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.7.0-dev.20240919#code/PTAEAsBdIBwZwFwgCYFMBuqA2B7GqAnAOgFscAvASyywEMicCBzYVAOwFoBVAZWGRwBjOMADqqAEbAAUrXS0eggpRiRgAJVQAzQu0GpgAcVwTaWAPoB5CQCtUgyCJ6o1ySlp0E9qACQAGAChBHDY4SFAcZGQ4UABeUDZUAHdQZ0gACgBtAEYAGlAAZnyAVnyAdnyATgBdAEoAbiCQsNA4AEcAV1ovGPjElLSsvNAAFiq6xuDQnCxUIlwmdMjoojcPXTZ9dPauntqG0BBUl3SC2tAAb0KS8tAAXyA

💻 Code

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference$0
const odds = new Set([1, 3, 5, 7, 9]);
const squares = new Set([1, 4, 9]);
console.log(odds.difference(squares)); // Set(3) { 3, 5, 7 }

🙁 Actual behavior

Property 'difference' does not exist on type 'Set<number>'.ts(2339)

TypeScript does not recognize the property.

🙂 Expected behavior

I expected TypeScript to recognize the property, since:

  1. MDN confirms it is widely available
  2. Add types for stage 3 "set methods" proposal #57228 and add types for set methods proposal #57230 seem to have accepted and merged this back in May.

Why is the compiler still showing that it isn't recognized?

Additional information about the issue

No response

Activity

  1. ghost closed this as completedon Sep 20, 2024
  2. itsramiel commented on Sep 20, 2024

    @itsramiel

    @occassionally why did you close this? How did you resolve the issue?

  3. ghost reopened this on Sep 20, 2024
  4. jcalz commented on Sep 20, 2024

    @jcalz
    Contributor

    Make sure your --target is for a version of JavaScript that supports this. In this case, esnext: playground link

  5. ghost closed this as completedon Sep 22, 2024
  6. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions