且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

错误 TS2339:属性 'split' 不存在于类型 'string | 中.细绳[]'.类型 'string[]' 上不存在属性 'split'

更新时间:2022-06-16 02:23:51

您尝试调用 split 的类型是 string|string[],这意味着value 可以是 stringstring[],为了让 TypeScript 满意,两种类型都必须有 split 方法.如果您确信它始终是一个字符串,请在调用 split 之前更新定义(如果可能)或强制转换为 string:

The type you are trying to invoke split on is string|string[], which means that value may be either a string or a string[], in order for TypeScript to be happy, BOTH types must have a split method. If you are confident that it will always be a string, either update the definition (if possible) or cast to a string before calling split:

(<string>req.headers.authorization).split

(req.headers.authorization as string).split