Loading [MathJax]/jax/input/TeX/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >typescript-exercises(十二)

typescript-exercises(十二)

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

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

题目:

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

报错:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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
运行
AI代码解释
复制
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 删除。

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

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
typescript-exercises(六)
阿超
2024/11/02
960
typescript-exercises(十四)
阿超
2024/11/10
860
typescript-exercises(五)
此处主要考察Partial<Type>的使用以及Omit<Type, Keys>的使用
阿超
2024/11/01
870
typescript-exercises(二)
阿超
2024/10/29
1030
typescript-exercises(十)
https://www.typescriptlang.org/docs/handbook/2/mapped-types.html
阿超
2024/11/06
930
typescript-exercises(八)
阿超
2024/11/04
800
typescript-exercises(十三)
阿超
2024/11/09
920
typescript-exercises(七)
阿超
2024/11/03
1090
typescript-exercises(十五)
阿超
2024/11/11
1320
typescript-exercises(三)
阿超
2024/10/30
930
typescript-exercises(四)
阿超
2024/10/31
1300
Typescript笔记
数值类型有很不止 number, bigint也是。同时值的话可以是十进制,二进制,还可以是NaN。
踏浪
2020/11/05
6110
Typescript学习笔记,从入门到精通,持续记录
TypeScript 最大的优势之一便是增强了编辑器和 IDE 的功能,包括代码补全、接口提示、跳转到定义、重构等。
房东的狗丶
2023/02/17
2.2K0
TypeScript学习笔记(二)—— TypeScript基础
JavaScript 的类型分为两种:原始数据类型(Primitive data types)和对象类型(Object types)。
张果
2022/10/04
5.4K0
TypeScript学习笔记(二)—— TypeScript基础
TypeScript学习笔记(四)—— TypeScript提高
Type又叫类型别名(type alias),作用是给一个类型起一个新名字,不仅支持interface定义的对象结构,还支持基本类型、联合类型、交叉类型、元组等任何你需要手写的类型。
张果
2022/10/04
2.6K0
TypeScript学习笔记(四)—— TypeScript提高
【TypeScript】010-类型别名、字符串字面量类型、元组、枚举
上例中,我们使用 type 定了一个字符串字面量类型 EventNames,它只能取三种字符串中的一种。
訾博ZiBo
2025/01/06
1890
TypeScript infer 关键字
在 TypeScript 中我们能够很方便地从复合类型中提取出单个类型,以数组、元组或对象为例,我们可以通过成员访问的语法来提取数组、元组或对象中元素或属性的类型,具体示例如下:
阿宝哥
2020/03/12
1.4K0
Typescript: Getting Started
Typescript Installation Typescript export error: XXX is not a module Could not find a declaration file for module 'xxx'. References Typescript Installation Create a Node.js project package.json. Quick one : npm init -y Add TypeScript (npm install ty
szhshp
2022/09/21
7090
【TypeScript】009-内置对象
TypeScript 核心库的定义文件中定义了所有浏览器环境需要用到的类型,并且是预置在 TypeScript 中的。
訾博ZiBo
2025/01/06
1630
TypeScript 超详细入门讲解
当我们需要将 unknown 类型的变量赋值给其他类型的变量的时候,我们可以给他指定类型
小丞同学
2021/10/08
8010
相关推荐
typescript-exercises(六)
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档