前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >typescript-exercises(十二)

typescript-exercises(十二)

作者头像
阿超
发布2024-11-08 09:27:42
发布2024-11-08 09:27:42
7600
代码可运行
举报
文章被收录于专栏:快乐阿超快乐阿超
运行总次数:0
代码可运行

人民是土壤,它含有要切事物发展所必需的生命汁液;而个人则是这土壤上的花朵 与果实。——别林斯基

题目:

代码语言:javascript
代码运行次数:0
复制
declare module 'stats' {
    export function getMaxIndex(input: unknown, comparator: unknown): unknown;
}

报错:

代码语言:javascript
代码运行次数:0
复制
index.ts(3,5): error TS2305: Module '"stats"' has no exported member 'getMaxElement'.
index.ts(4,5): error TS2724: Module '"stats"' has no exported member 'getMinIndex'. Did you mean 'getMaxIndex'?
index.ts(5,5): error TS2305: Module '"stats"' has no exported member 'getMinElement'.
index.ts(6,5): error TS2305: Module '"stats"' has no exported member 'getMedianIndex'.
index.ts(7,5): error TS2305: Module '"stats"' has no exported member 'getMedianElement'.
index.ts(8,5): error TS2305: Module '"stats"' has no exported member 'getAverageValue'.
index.ts(126,37): error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'number'.
index.ts(149,37): error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'number'.
test.ts(13,5): error TS2344: Type 'false' does not satisfy the constraint 'true'.
test.ts(20,5): error TS2344: Type 'false' does not satisfy the constraint 'true'.
test.ts(27,5): error TS2344: Type 'false' does not satisfy the constraint 'true'.
test.ts(34,5): error TS2344: Type 'false' does not satisfy the constraint 'true'.
test.ts(41,5): error TS2344: Type 'false' does not satisfy the constraint 'true'.
test.ts(48,5): error TS2344: Type 'false' does not satisfy the constraint 'true'.
test.ts(55,5): error TS2344: Type 'false' does not satisfy the constraint 'true'.

答案:

代码语言:javascript
代码运行次数:0
复制
declare module 'stats' {
    export function getMaxIndex<T>(input: T[], comparator: (a:T, b:T) => number): number;
    export function getMaxElement<T>(input: T[], comparator: (a:T, b:T) => number): T | null;
    export function getMinIndex<T>(input: T[], comparator: (a:T, b:T) => number): number;
    export function getMinElement<T>(input: T[], comparator: (a:T, b:T) => number): T | null;
    export function getMedianIndex<T>(input: T[], comparator: (a:T, b:T) => number): number;
    export function getMedianElement<T>(input: T[], comparator: (a:T, b:T) => number): T | null;
    export function getAverageValue<T>(input: T[], getValue: (item: T) => number): number | null;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-11-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档