In the code below I would expect the find function to return undefined | BufferEncoding
, the same type as the Map has. But undefined | string
is returned. How come?
const chartdetToFsEncodings = new Map<string, BufferEncoding>([
["UTF-8", "utf8"],
["UTF-16LE", "utf16le"],
]);
const supportedEncoding = analyse(buffer)
.map((match) => match.name)
.find((name) =>
chartdetToFsEncodings.get(name)
) as BufferEncoding;
我尝试将Map设置为const,但是出现了一些语法错误。
const chartdetToFsEncodings = new Map<string, BufferEncoding>([
["UTF-8", "utf8"],
["UTF-16LE", "utf16le"],
]) as const;