Spread operator with wrong optional property raises error on incorrect source line
#51,376 opened on 2022幎11æ1æ¥
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
Bug Report
ð Search Terms
spread error wrong line
ð Version & Regression Information
- This is the behavior in every version I tried, [not applied: and I reviewed the FAQ for entries about]. I tried on v3.3.3 and also on nightly.
⯠Playground Link
Playground link with relevant code
ð» Code
type Item = {
attribute: string;
};
const result: Partial<Record<'attribute', string | null>> = {
attribute: "",
}
const item: Item ={
attribute: "",
...result,
}
ð Actual behavior
This code is, of course, an error. The surprising thing is where the error is raised. In this case the line reading attribute: "", will be highlighted with Type 'string | null' is not assignable to type 'string'.
In this simple reproduction the error is clear, but when I discovered it the types were more complicated and there were a dozen or more attributes in between the scary red line and the offending spread.
ð Expected behavior
The diagnostic error would be much more helpful if the spread containing the invalid property was highlighted instead of the property which actually has correct types.