-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
Description
I have a map of type:
Map<string, string | string[]>
I call the get() methods after I run a has() check on the Map Object, and flow warns me about incompatible type. Why?
Here is part of my code:
if (sectionBody.has(key)) {
const prevVal: string | string[] = sectionBody.get(key);
sectionBody.set(key, [].concat(prevVal, value));
}And this is the error message
74: const prevVal: string | string[] = sectionBody.get(key);
^^^^^^^^^^^^^^^^^^^^ call of method `get`
74: const prevVal: string | string[] = sectionBody.get(key);
^^^^^^^^^^^^^^^^^^^^ undefined. This type is incompatible with
74: const prevVal: string | string[] = sectionBody.get(key);
^^^^^^^^^^^^^^^^^ union: string | array type
Member 1:
74: const prevVal: string | string[] = sectionBody.get(key);
^^^^^^ string
Error:
74: const prevVal: string | string[] = sectionBody.get(key);
^^^^^^^^^^^^^^^^^^^^ undefined. This type is incompatible with
74: const prevVal: string | string[] = sectionBody.get(key);
^^^^^^ string
Member 2:
74: const prevVal: string | string[] = sectionBody.get(key);
^^^^^^^^ array type
Error:
74: const prevVal: string | string[] = sectionBody.get(key);
^^^^^^^^^^^^^^^^^^^^ undefined. This type is incompatible with
74: const prevVal: string | string[] = sectionBody.get(key);
^^^^^^^^ array type
Reactions are currently unavailable