Spread syntax for intersection types: { ...Foo, bar: number }
= Foo & { bar: number }
#54890
Closed
5 tasks done
Suggestion
When merging records in javascript, we use the spread syntax:
However in typescript we can't:
We have to use
type Bar = Foo & { b: number }
instead.This gets ugly really fast when the record has many fields. For example how should I format this function declaration?
The first version doesn't scale if we add more
&
s. The second version is the best I can come up with but it's so ugly and awkward.Compare it to this:
🔍 Search Terms
spread, syntax, record, intersection types
✅ Viability Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: