shjames
shjames
'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015...
function fn(x: string): void; function fn() { // ... } 上面函数重载的写法中,在函数实现部分,为什么fn()直接这样写,没有带参数也没有报错,是因为假如在函数实现中,如果没有传参,就直接跳过参数部分的类型检查啦?
图片加载失败了
请问大佬,这个泛型写法,什么时候写在前面,什么时候写在后面有口诀吗? ``` //这里是写在后面 class GenericNumber { zeroValue: NumType; add: (x: NumType, y: NumType) => NumType; } ``` ``` //写在前面 interface GenericIdentityFn { (arg: Type): Type; } ```
下面的函数体怎么写才能不报红?  
@kwSir-chen > > 下面的函数体怎么写才能不报红?   > > 可能这么写 > ``` > function createLabel( > idOrName: T > ): NameOrId { > if (typeof idOrName === 'number') { > return...
@riskers > > 下面的函数体怎么写才能不报红?   > > ```typescript > > function createLabel(idOrName: number): IdLabel; > function createLabel(idOrName: string): NameLabel; > function createLabel(idOrName: number | string) : IdLabel | NameLabel...
@riskers > @shjames https://stackoverflow.com/questions/60475431/generic-type-extending-union-is-not-narrowed-by-type-guard > > 可以参考这个问题的回答 > > `idOrName` 是参数,可能是 string 也可能是 number,这是编译期不能决定的,所以没办法通过 `NameOrId` 来约束返回值 > > 好的,感谢
ReadonlyArray类型不能修改指的是不能使用类似数组push的一些方法吗?比如let x: readonly string[] = [];x=['1','2']; 直接这样些并没有报错
 请问大佬,为什么上面这种间接赋值会报错?而下面这种直接赋值就不会? 