我是TypeScript的新手,并且函数中的可选参数有一点问题.我在Visual Studio Code中为query参数获得了以下错误(参见屏幕截图).我真的不明白这个错误,因为我将类型定义为string.那么为什么我会收到这个错误?
消息:'类型'字符串的参数| undefined'不能赋值给'string'类型的参数.类型'undefined'不能分配给'string'类型
public async fetchPut<T>(requestURL: string, body: TBody, query?: string): Promise<T> {
const finalRequestOption: IFetchOption = Object.assign({
method: 'PUT',
headers: this.headers
}, { body });
const response: Response = await this.httpClient.fetch(
this.getRequestURL(requestURL, query),
finalRequestOption);
return response.json();
}
Run Code Online (Sandbox Code Playgroud) 我使用静态构建包将 React 应用程序部署到 Cloud Foundry。目标是使应用程序可以在domain.com/路径下访问。所以我根据他的博客文章配置了路线: https: //www.cloudfoundry.org/context-path-routing/
另外,我pushstate: enabled在静态文件中进行了设置,并将上下文路径添加到静态资源 URLS 中;例如,样式表的 URL 是domain.com/path/static/style.css。当我访问domain.com/path 时,我得到了index.html 文件。但是,找不到 index.html 文件中链接的静态资源,而是找到了索引文件。如果在服务器上找不到资源,这是推送状态路由的默认行为。
为了pushstate: enabled在“子目录”中运行应用程序,我还需要配置什么吗?