#How to assign new value to an interface
12 messages · Page 1 of 1 (latest)
interface Foo { bar: string; }
type FooWithNumber = Omit<Foo, 'bar'> & { bar: number; };
// ^? - type FooWithNumber = Omit<Foo, "bar"> & {
// bar: number;
// }
This worked, thanks. What is the reasoning for not allowing the first syntax, do you know?
it's invalid semantically, not syntactically
& is an analog for set intersection, which is commutative
"override" is not commutative
{ bar: string } & { bar: number } -> { bar: string & number } and you can't have something that's both a string and a number (for primitives) so you get never out of that
never is a type that has no possible value, it's an analog to the empty set
sidenote; since 'bar' is the only property in Foo, Omit<Foo, 'bar'> is just {}
OK thanks