Skip to content

Linter didn't detect { [x: string]: any; }[] !== { [x: string]: any; } #62087

@wanapichpongsa

Description

@wanapichpongsa

🔎 Search Terms

"linter"

🕗 Version & Regression Information

I saw this error in Typescript 5.8.2. I'm not sure if this has been the case for how long but I'm quite busy and just wanted to notify the Typescript team in case its important.

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABACwIYGdkFtUAcAqcASgKYRwBOAJgBRqY64BciA3ogNoAeL6UFMMAHMAui1RgAnogC+ASjYAoRCsQUSUEBSQB5AEYArMlAB0JMPxgl0dDNjxyT6qiAgkaNdRAA0nANYkkr4AbqgANiAkIgoAvAB8SqpJamQcAZIiiDGIoREkANzKySrqmtopEIVJMr6sMogYiKTk1AA8fALCvhKScXKKMoqK5GB8DRQUqJI6wAASdozoLOzcvJbCYg1SshyZWZxFKqyHyTDoAPpQyGcsAESo53ogQgD8tyc1J8fFKmeX10tEPdHs83h9vF8Tkk-lcbkCHk9Xu9qooREMRmNUBMpjNmpQqOh9vR7ARiGR8TQsZNpnMFnh0HJChi4GESCYwnAhJTsTS8dQGYVFAB6ABUih0AFV8AAFKVMRTfIEABluyxOtxhANV8JBSKKnxUtwAjNrFYbNWdtcDEWCVAagQAmU3qi3oK0I0HI2QDIYAOTgUBILAAkoh0CQSIhAMgEiFDQki6EJVKmSfUiAMIDG+JIzhQdNw6BMiAAQiAoIgqHBEJI4CAwxGUHAAO7V2uICASADk5czkagklw1ggAlw5YAgjzEFgNMg4ATEHoyKhe4g4MBELDCYjEOAqBpjCQqAvpFdI2FBIGKC9FCKheiEGN0oTssneeT+SZGJ4yFkEvojNAJhPt+EByHIQA

💻 Code

function hashmapToRecord(hashmap: { [x: string]: any }) {
    return Object.entries(hashmap).reduce((rec, [key, value]) => {
        rec[key] = value;
        return rec;
    }, {} as Record<string, any>)
}

const arrayOfHashmaps: { [x: string]: any }[]  = [
    {
        is_this: "a_bug?"
    },
    {
        is_this: "a_bug?"
    },
    {
        is_this: "a_bug?"
    }
]

const arrayOfRecords = hashmapToRecord(arrayOfHashmaps);
console.log(arrayOfRecords);

/*
OUTPUT:
{
  "0": {
    "is_this": "a_bug?"
  },
  "1": {
    "is_this": "a_bug?"
  },
  "2": {
    "is_this": "a_bug?"
  }
}

Note: I see – I guess arrays are just ordered hashmaps. But do you see how the type interpreter thinks rec is any instead of { [x: string] : any }?
*/

const keys = arrayOfRecords.map((rec) => Object.keys(rec)) // <- There would be a red squiggly line on rec

🙁 Actual behavior

variable of type { [x: string]: any; }[] was passed as an argument of a function with parameter type { [x: string]: any; } but no linter error. Not sure if the difference is trivial.

🙂 Expected behavior

{ [x: string]: any; }[] shouldn't be treated the same as { [x: string]: any; } unless I am naïve about a functional reason.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy