Skip to content

Commit 1f5e929

Browse files
committedDec 31, 2024·
docs(operator): fixed typo
1 parent 1725cbb commit 1f5e929

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed
 

‎docs/operator.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ const palette: Record<Colors, string|RGB> = {
660660
const greenComponent = palette.green.substring(1, 6); // 报错
661661
```
662662

663-
上面示例中,`palette.green`属性调用`substring()`方法会报错,原因是这个方法只有字符串才有,而`palette.green`的类型是`srting|RGB`,除了字符串,还可能是元组`RGB`,而元组并不存在`substring()`方法,所以报错了。
663+
上面示例中,`palette.green`属性调用`substring()`方法会报错,原因是这个方法只有字符串才有,而`palette.green`的类型是`string|RGB`,除了字符串,还可能是元组`RGB`,而元组并不存在`substring()`方法,所以报错了。
664664

665665
如果要避免报错,要么精确给出变量`palette`每个属性的类型,要么对`palette.green`的值进行类型缩小。两种做法都比较麻烦,也不是很有必要。
666666

0 commit comments

Comments
 (0)
Please sign in to comment.