I am using strict mode for the following code.
Trying to assign an object value from a Map.
It is granted that the value I am getting from the Map isn't undefined but strict mode giving the following error Type A[]|undefined isn't assignable to type A[].
How can I pass this compiler issue?
let key = "foo"
leaderboardRecords: A[] = [];
leaderboardRecordsbyRegion: Map<string, A[]> = new Map<string, A[]>();
if (!leaderboardRecordsbyRegion.has(key)) {
leaderboardRecordsbyRegion.set(key, fetchData());
}
leaderboardRecords = leaderboardRecordsbyRegion.get(key);
fetchData()would beA[]|undefined. So error says that types are not matching. SimpleleaderboardRecords = leaderboardRecordsbyRegion.get(key)!;fetchData()returnsa promise<A[]>