xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

TypeScript & Type Challenges All In One

TypeScript & Type Challenges All In One

image

Collection of TypeScript type challenges with online judge

https://tsch.js.org/

https://github.com/type-challenges/type-challenges

demos

这个简单的提问希望让你可以快速上手 Type Challenges。
在这里,我们使用了一些神奇的技巧让 TypeScript 通过自身的类型系统来实现自动判题。

在这个挑战中,你需要修改下方的代码使得测试用例通过(使其没有类型错误)。

  // 期望是一个 string 类型
  type HelloWorld = any

  // 你需要使得如下这行不会抛出异常
  type test = Expect<Equal<HelloWorld, string>>

接受挑战

/* _____________ 你的代码 _____________ */

// type HelloWorld = any // expected to be a string
type HelloWorld = string;

/* _____________ 测试用例 _____________ */

import type { Equal, Expect, NotAny } from '@type-challenges/utils'

type cases = [
  Expect<NotAny<HelloWorld>>,
  Expect<Equal<HelloWorld, string>>,
]

分享你的解答:https://tsch.js.org/13/answer/zh-CN

查看解答:https://tsch.js.org/13/solutions

更多题目:https://tsch.js.org/zh-CN

refs

https://github.com/web-full-stack/type-challenges

https://github.com/type-challenges/type-challenges/issues/19615



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2022-11-22 23:03  xgqfrms  阅读(102)  评论(1编辑  收藏  举报