李恒道 发表于 2022-7-17 23:44:19

typescript类型体操记录贴(一)Hello World

# 前文
因为学的ts不是特别扎实...
一之哥开嘲讽技能之后
决定痛定思痛
每天做一题类型体操
地址https://github.com/type-challenges/type-challenges
# 解题
今天第一题
https://github.com/type-challenges/type-challenges/blob/main/questions/00013-warm-hello-world/README.md
```
Hello, World!

In Type Challenges, we use the type system itself to do the assertion.

For this challenge, you will need to change the following code to make the tests pass (no type check errors).
```
翻译:
你好世界
在类型体操,我们使用类型系统自身进行断言
对于这个挑战,你需要改变接下来的代码通过测试(没有类型错误)
```
// expected to be string
type HelloWorld = any
```
期待一个string
```
// you should make this work
type test = Expect<Equal<HelloWorld, string>>
```
你应该让这个代码正常工作
Equal泛型,判断类型相等
Expect泛型,期待是一个true类型
那么这个代码就是判断HelloWorld类型是否等于string得到结果
然后根据结果判断是否为true
我们默认是
type HelloWorld = any
any类型
直接将any改为string即可
![图片.png](data/attachment/forum/202207/17/234418v5eksxxj9xe92l52.png)
通关~
# 感言
山东菏泽曹县牛逼六六六我累宝贝
页: [1]
查看完整版本: typescript类型体操记录贴(一)Hello World