Incorrect type inference in Object.entries and Object.values if type has optional value
Opened this issue ยท 1 comments
Crinax commented
๐ Search Terms
object.entries, object.values, type inference, incorrect type inference,
๐ Version & Regression Information
- This changed between versions 4.5.5 and 6.0 (nightly)
โฏ Playground Link
๐ป Code
type SomeKeys = 'a' | 'b' | 'c';
type Value = string;
type TestObj = {
[k in SomeKeys]?: Value;
}
let e: TestObj = {
a: undefined
}
// Should be [string, string | undefined][]
let eEntries = Object.entries(e); // [string, string][]
// Should be (string | undefined)[]
let eValues = Object.values(e); // string[]๐ Actual behavior
- Type of result of
Object.entriesis a[string, T] - Type of result of
Object.valuesis aT[]
๐ Expected behavior
- Type of result of
Object.entriesshould be a[string, T | undefined]if optional property exists - Type of result of
Object.valuesshould be a(T | undefined)[]if optional property exists
Additional information about the issue
No response
MartinJohns commented
Duplicate of #52045.