microsoft / microsoft/TypeScript
Type error not indicated when spreading into a JSX component whose props type is defined as interface
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Bug Report
🔎 Search Terms
react, component props, interface type, spread
🕗 Version & Regression Information
Bug present in 3.3.3 (oldest version available on Playground), as well as Nightly.
⏯ Playground Link
Playground link with relevant code
💻 Code
import * as React from 'react'
// Change interface to a type declaration and the bug disappears.
interface Props {}
// type Props = {}
// Change 'Props' => '{}' (ie. inline the type) and the bug disappears.
function Component(_: Props) {
return <div>C2</div>
}
export function Bug() {
const props = { opt: "1" } as const
// Should be a type error, since Component doesn't accept 'opt' prop
return <Component {...props} />
}
🙁 Actual behavior
No error is indicated.
Error is indicated correctly when interface is changed to a type declaration, or the type is inlined.
🙂 Expected behavior
TypeScript should indicate a type error since Component doesn't accept the 'opt' prop.
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 linked TypeScript Playground reproduction and compare JSX spread checking when Props is an interface, a type alias, or an inline type. Trace the type-checking path for the Component call and verify the fix by restoring the expected error for the extra opt prop while preserving the other cases.
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
- 35/100