type a = {
a: number
b: {d: string}[]
}
type b = {
c : string
b: {f: number}[]
}
type l = a & b
const ab: l = {a: 1, c: '', b: [{d: '', f:1}]}
const ac: l['b'] = [{ d: '', f: 1}]
After merging types a
and b
into type l
why does const ab
of type l
work while const ac
of type l['b']
does not work?
i tried to write this code on vscode and got this error on const ac :
Type '{ d: string; f: number; }[]' is not assignable to type '{ d: string; }[] & { f: number; }[]'.
Types of property 'pop' are incompatible.
Type '() => { d: string; f: number; }' is not assignable to type '(() => { d: string; }) & (() => { f: number; })'.
Type '() => { d: string; f: number; }' is not assignable to type '() => { d: string; }'.
Type '{ d: string; f: number; }' is not assignable to type '{ d: string; }'.
Object literal may only specify known properties, and 'f' does not exist in type '{ d: string; }'.
Why does type l['b']
not contain the merged type {d: string, f: number}[]
from type { d: string; }[] & { f: number; }[]
while it does on type l
?