microsoft / microsoft/TypeScript
Object spread drops index signature
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.0.1
Search Terms:
spread index signature, spread indexer
Code
declare var v: Record<string, string>;
let v2 = {...v}; // works
let v3 = {a: '', ...v}; // index signature lost
let v4 = {...v, a: ''}; // same as above
let v5 = {a: 1, ...v}; // index signature lost, should be '{a: number, [x: string]: number | string}'
let v6 = {[Number()]: 1, ...v}; // empty object type ò,Ó, should be '{[x: string]: number | string}'
Expected behavior:
Index signature exists on all object types.
Actual behavior:
Index signature is lost if object literal contains another property assignment. I'm not entirely sure what the type of v6 should be.
Related Issues:
#16694
#16373
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
Start with the TypeScript 3.0.1 examples in the issue and reproduce the inferred types through the linked Playground. Review related issues #16694 and #16373 for prior discussion and expected behavior, especially for v5 and v6. Done means establishing and implementing consistent index-signature behavior for the reported object-spread cases, with coverage for the examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 39/100