首页 > 解决方案 > 使用 Typescript 强制数组中的类型

问题描述

尝试为其分配严格类型时,我继续收到打字稿错误。如何将返回数组中的每个项目设置为它自己的类型。我想将数组中的每个项目定义为明确的类型,这样我就可以在我的文档中使用它们,而不必as string每次使用它们时都编写。

类型 '(string | string[])[]' 不能分配给类型 '[any, string, any, string[]]'。目标需要 4 个元素,但源可能有较少的.ts(2322)

    const [, currentRoute, , requiredRoutes]: [any, string, any, string[]] = useDocumentCaptureRoute(viewModel);

标签: javascripttypescript

解决方案


推荐阅读