Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When inferring the type of Object.values, optional properties are not considered #60883

Closed
brestmoor opened this issue Dec 30, 2024 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@brestmoor
Copy link

πŸ”Ž Search Terms

"Object.keys Record", "record with field"

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/?ssl=7&ssc=20&pln=1&pc=1#code/C4TwDgpgBAglC8UBKEDGB7ATgEwDwGdhMBLAOwHMAaKQkigPigDIoBvUgQwFsIB+ALhpEy5AL4AocRlKEoHQXESsJHAHSceCKAFdS2CADMyEbFPQzgUAG4cANtoj4tAeQBGAKzTBVN+44AUHACU4gD0ob4OTqCQUMROtCIA2gC6UADuABYQpHG5BhyolsSW0sAcZE4A5Lr6RqQmVWYy6LYQqrbo5P6RjkFAA

πŸ’» Code

type A = Record<string, string> & {name?: string}

const a: A = {}
a.name = undefined
const values = Object.values(a)
//values type is string[] when in fact it contains 'undefined'
console.log(values)

πŸ™ Actual behavior

The type does not reflect the reality, the type of values is string[] where in fact the array can contain undefined

πŸ™‚ Expected behavior

I expect typescript to infer the type to be (string | undefined)[]

Additional information about the issue

No response

@MartinJohns
Copy link
Contributor

#44494

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 2, 2025
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants