microsoft / microsoft/TypeScript
Missing error when mistyped value overwrites property of spreaded generic type parameter
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
generic argument, rest spread, false positive
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about object spread and generics
I found a few relevant issues, but none of them fully correspond to the current one:
- https://github.com/microsoft/TypeScript/issues/35858
- https://github.com/microsoft/TypeScript/issues/38469
- https://github.com/microsoft/TypeScript/issues/30129
⏯ Playground Link
Playground link with relevant code
💻 Code
interface InputProps {
value: string;
}
const getProps = (props: InputProps): InputProps => ({
...props,
value: 123, // when there is no generic type, it shows an error, as expected
});
const getPropsGenericNoSpead = <T extends InputProps>(props: T): T => {
const newProps = {...props};
newProps.value = 123; // also error, as expected
return newProps;
};
const getPropsGeneric = <T extends InputProps>(props: T): T => ({
...props,
value: 123, // no error here
});
🙁 Actual behavior
Typescript allows assigning incompatible types
🙂 Expected behavior
Typescript shows an error
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 Playground example and compare the generic spread case with the non-generic and non-spread cases shown in the report. Trace the type-checking behavior for the value: 123 assignment in the generic object spread, and consider the issue done when TypeScript reports the expected incompatibility without regressing the other 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
- 45/100