-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
🔎 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
💻 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
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug