The TS2532 error in Typescript is triggered for both occurrences of conn.get(aa)
below. However, it should be noted that both access points are protected by if(conn.has(aa))
, indicating that the get
operation is valid and not undefined.
const conn: Map<string, {from: string[]; to: string[]}> = new Map();
const aa = "aa";
if(conn.has(aa)) conn.get(aa).to.push("bb");
conn.set("aa", {from: [], to: []});
if(conn.has(aa)) conn.get(aa).to.push("bb");
Even when checking for existence in this manner:
if(conn.has(aa) && conn.get(aa)) conn.get(aa).to.push("bb");
Typescript still raises an issue with conn.get(aa)
. Can you identify the underlying problem that I may be overlooking? Thank you!