-
Notifications
You must be signed in to change notification settings - Fork 71
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
fromEntries should return partial type #225
Comments
This issue is about how sound TypeScript's type system is. This level of soundness is common in TypeScript, much like a case where you access an element in an array: const arr = [1,2,3];
arr[100] // number; According to TypeScript's design goals, there is a emphasis on balancing productivity with complete type soundness. Therefore, I think keeping |
Sorry, but I'm not following. What's the benefit of emitting knowingly incorrect type in this particular case? Basically, the user is forced to do this every time: const res = fromEntries(...)
return res as Partial<typeof res> What do we lose if |
If you do it as you suggest, conversely, you'd still need to perform a null check, even when the input to const res = fromEntries([['a', 1], ['b', 2]])
// typeof res : { a?: number, b?: number }
if (res.a !== undefined) {
console.log(res.a)
} When the input to |
I thought the whole point of |
I understand your statement thoroughly, and I agree with your point. However, it ultimately boils down to a trade-off. The type Obj = { type: 'A' | 'B' | 'C' };
groupBy(
({ type }) => type,
list as Obj[]
) // `{ A: Obj, B: Obj, C: Obj }` or `{ A?: Obj, B?: Obj, C?: Obj }` ? I think that inferring it as |
Bug Report
💻 Code
🙁 Actual behavior
There is no typing error. The code crashes.
🙂 Expected behavior
Typing error:
'res.foo' is possibly 'undefined'.
Version Information
The text was updated successfully, but these errors were encountered: