tra*_*ang 0 arrays tuples optional-parameters typescript
我想声明一个 Typescript 数组类型,其中最后一个元素是可选的。有没有什么优雅的方法来实现这一目标?
const test = (a: [string, string, any | undefined]) => console.log(a)
test(['foo', 'bar'])
Run Code Online (Sandbox Code Playgroud)
在test(...)
函数调用中,ts 详细说明此错误
Argument of type '[string, string]' is not assignable to parameter of type '[string, string, any]'.
Property '2' is missing in type '[string, string]' but required in type '[string, string, any]'.(2345)
Run Code Online (Sandbox Code Playgroud)
const test = (a: [string, string, any?]) => console.log(a)
test(['foo', 'bar'])
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。
归档时间: |
|
查看次数: |
156 次 |
最近记录: |