microsoft / microsoft/TypeScript
Empty type inferred by Object.entries
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 2.7.1
Search Terms: Object entries empty TS2365
Code
let o: any = {x: 5};
let p = Object.entries(o).map(([k, v]) => v + 1);
Compile command: tsc --lib es2017,es2017.object a.ts
Expected behavior:
This should compile without any error, assuming v: any.
This was the case for Typescript 2.6.2 at least.
Actual behavior:
(3,43): error TS2365: Operator '+' cannot be applied to types '{}' and '1'.
Following codes compile without errors:
let o: object = {x: 5};
let p = Object.entries(o).map(([k, v]) => v + 1);
let o: any = {x: 5};
let p = Object.entries(o).map(([k, v]: [any, any]) => v + 1);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report in a.ts with TypeScript 2.7.1 using tsc --lib es2017,es2017.object a.ts, then compare the Object.entries inference with the 2.6.2 behavior described here. Start by tracing the typings and inferred tuple element types for the shown map callback. Done when the original example compiles as expected without breaking the explicitly annotated alternatives.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100