好的,我刚开始打字,我对以下代码中的Object is possibly undefined错误感到困惑(这段代码已高度缩写):
interface IUrlData {
wsPropertyNames: string[];
routeValuesRegExp: RegExp;
}
export default class Builder implements IBuilder {
private _urlData?: IUrlData;
async build(): Promise<IConfig> {
// VS Code Intellisense says that this._urlData is IUrlData | undefined in the next line.
if (this._urlData) {
// In this next line, VS Code Intellisense says this._urlData is IUrlData (no undefined, so narrowed by the if).
this._urlData.wsPropertyNames.forEach((value) => {
const obj = wjConfig[value];
if (isConfig(obj)) {
// This is where the error happens. All of the sudden, this._urlData is back to IUrlData | undefined.
makeWsUrlFunctions(obj, this._urlData.routeValuesRegExp);
}
});
}
}
}
那么,有没有人可以帮我指出我的错误,或者提供一个解决办法,如果这是由于错误或类似的错误而被打字搞砸的东西?
非常感谢.