我已经看到了关于字符串数组而不是实际字符串提到的这个错误.我有一个带有该行的TypeScript文件
if (!bus.lineInfo.PublishedLineName.includes(input)) {
Run Code Online (Sandbox Code Playgroud)
这给了我一个错误
TS2339: Property 'includes' does not exist on type 'string'.
Run Code Online (Sandbox Code Playgroud)
bus是一个实现bus接口的变量:
interface bus {
"lineInfo": {
"PublishedLineName": string,
"DestinationName": string, // The headsign of the bus
"Color": string,
"TextColor": boolean | string // false if this is "FFFFFF", otherwise it's the color
},
"warnings": boolean | busWarnings
"marker"?: google.maps.Marker,
"result"?: JQuery // The search result that appears in the sidebar
}
Run Code Online (Sandbox Code Playgroud)
lineInfo.PublishedLineName声明为a string,并且String.prototype.includes() 是根据MDN的函数,那么为什么TypeScript编译器会抱怨缺少的属性/方法?