microsoft / microsoft/TypeScript

spreading generic type disables excess property checking

Open
#30,129 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: check: Excess Property Checking
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.3.3333

Search Terms: generic spread

Code

function spread<T extends {foo: string}>(p: T): {foo: string} {
    return {...p, bar: ''};
}

Expected behavior:

Excess property error for bar.

Actual behavior:

No error.

Playground Link: http://www.typescriptlang.org/play/#src=function%20spread%3CT%20extends%20%7Bfoo%3A%20string%7D%3E(p%3A%20T)%3A%20%7Bfoo%3A%20string%7D%20%7B%0D%0A%20%20%20%20return%20%7B...p%2C%20bar%3A%20''%7D%3B%0D%0A%7D

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the TypeScript 3.3.3333 reproducer in the issue and investigate how excess-property checking handles an object spread from a generic type. Done means the sample reports an excess-property error for bar and a regression test covers the behavior; no source file or test path is named in the issue.

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
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.