javascript - 使用 Typescript 强制数组中的类型
问题描述
尝试为其分配严格类型时,我继续收到打字稿错误。如何将返回数组中的每个项目设置为它自己的类型。我想将数组中的每个项目定义为明确的类型,这样我就可以在我的文档中使用它们,而不必as string
每次使用它们时都编写。
类型 '(string | string[])[]' 不能分配给类型 '[any, string, any, string[]]'。目标需要 4 个元素,但源可能有较少的.ts(2322)
const [, currentRoute, , requiredRoutes]: [any, string, any, string[]] = useDocumentCaptureRoute(viewModel);
解决方案
推荐阅读
- python - 主管不在容器内运行
- macos - gcc-10下架构x86_64的重复符号
- azure-devops - 我如何运行依赖于可以有条件地不运行的东西的作业?
- java - org.eclipse.persistence.exceptions.ConversionException 使用 JPA 将 Oracle TIMESTAMPTZ 转换为 java.util.Date 时
- reactjs - 根据其他值更改 Formik 选择器选项 - React Native
- regex - RegEx匹配Dialogflow中的特殊字符
- reactjs - React handlechange 只是更新每个字母而输入没有意识到它
- matlab - 如何从MATLAB中大型数据集的前几个数据中减去?
- java - 如果我当前的类 API 失败,如何从另一个类调用方法
- amazon-web-services - CodeBuild 将源 React 文件推送到 s3 而不是构建文件夹