例如:
dict_instance.get = my_wrapper(dict_instance.get)
答案 0 :(得分:0)
find
函数的定义是:
find(predicate: (value: T, index: number, obj: T[]) => boolean, thisArg?: any): T | undefined;
签名表明该值可以不确定。如果要告诉编译器该值不会是不确定的,只需在末尾添加!
:
const closestSize = ['small', 'large'].find((size) => !!map[size])!;
或
return map[closestSize]!;