Hurryliwei

Results 10 comments of Hurryliwei

最近公司没事,我看了两个礼拜的官方文档 看不懂好多地方,而且搜到的中文文档 运行全是报错,我还在掘金里面挨个知识点问,结果是因为文档的版本太老了! 谢谢大佬的分享,我也是从掘金上追来的从第一篇文章 看到现在的。

```ts type DescribableFunction = { description: string; (someArg: number): boolean; }; function doSomething(fn: DescribableFunction) { console.log(fn.description + " returned " + fn(6)); } ``` 这个调用签名中的 函数 如果实例使用的话 如何传参呢给doSomething(),我自己试过传参 编译不通过呀 大佬!...

> @Hurryliwei “如果实例使用?” 不知道是指什么意思?要不然写段预期的代码效果? 就是举个例子 写段预期的代码效果 这个只是做了一个定义 如何使用呢? 参数如何传递 参数的形式等等 写一个完整的呗 大佬 我有点没懂如何具体情况下使用 传参。

> @Hurryliwei 我明白了,这是使用的示例: > > ```ts > type DescribableFunction = { > description: string; > (someArg: number): boolean; > }; > function doSomething(fn: DescribableFunction) { > console.log(fn.description + " returned...

> @Hurryliwei 是的 学到了 大佬 文档中写的好多知识点 正好是我 看了官方文档却不懂的地方 但是又没google到这个知识点; 再次感谢您解答疑惑哦 希望您一直更新下去 为我们这些菜鸟答疑解惑

```ts interface Animal { name: string; } interface Dog extends Animal { breed: string; } interface NotOkay { [x: number]: Animal; // 'number' index type 'Animal' is not assignable to...

```ts type Either2dOr3d = [number, number, number?]; function setCoordinate(coord: Either2dOr3d) { const [x, y, z] = coord; const z: number | undefined console.log(`Provided coordinates had ${coord.length} dimensions`); // (property) length:...

> @Hurryliwei 我们看下这段代码相关的文字: > > > 虽然 TypeScript 可以同时支持 string 和 number 类型,但数字索引的返回类型一定要是字符索引返回类型的子类型。这是因为当使用一个数字进行索引的时候,JavaScript 实际上把它转成了一个字符串。这就意味着使用数字 100 进行索引跟使用字符串 100 索引,是一样的。 > > 所以修改为不报错的方法是把数字索引的返回类型设置为字符索引返回类型的子类型,比如这样: > > ```ts > interface Animal { > name:...

> @Hurryliwei 非常抱歉,setCoordinate 这段我写错了,其实 `const z: number | undefined` 这句其实是提示的效果, 我拷贝的时候忘记改成注释了……感谢指正,我已经修改了 > > ![image](https://user-images.githubusercontent.com/11458263/144993435-8069aea7-f864-47fc-8d78-4491fdadd4dd.png) 我是怕大家 不懂 这不是错误 大佬 您很棒

> @Hurryliwei 没事,微信勇敢来加,参与讨论和指正的同学我都直接邀请入群 那我加了哦 就是怕问多了 您会烦 也害怕打扰您工作