midwayjs / midway

🍔 A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade. Works on AWS, Alibaba Cloud, Tencent Cloud and traditional VM/Container. Super easy integrate with React and Vue. 🌈
https://www.midwayjs.org/
MIT License
7.4k stars 577 forks source link

官网快速入门的一些问题 #2879

Closed shad0whz closed 1 year ago

shad0whz commented 1 year ago

快速入门

首先是 http://www.weather.com.cn/data/sk/${cityId}.html 这个接口已经被弃用

其次:

import { Provide, makeHttpRequest } from '@midwayjs/core';
import { WeatherInfo } from '../interface';

@Provide()
export class WeatherService {
  async getWeather(cityId: string): Promise<WeatherInfo> {
    const result = await makeHttpRequest(`http://www.weather.com.cn/data/sk/${cityId}.html`, {
      dataType: 'json',
    });

    if (result.status === 200) {
      return result.data;
    }
  }
}

上述代码直接使用时会导致 Property 'weatherinfo' is missing in type '{}' but required in type 'Weather这个错误 虽然这个错误很新手,只需要将 return result.data; 改为return result.data as WeatherInfo; 但是我感觉官方文档还是应该避免这些错误,这让新手的体验很不好。

czy88840616 commented 1 year ago

不好意思,http://www.weather.com.cn/data/sk/101010100.html 接口属于网上的开放 api,我理解只要能访问,我们不太关心他是否废弃,既然提出,我们会进行修改。

ts 类型问题我们在示例库中已经调整,文档未更新的确是问题。

shad0whz commented 1 year ago

好的,第一个问题可能是我这边网络问题,早上尝试的时候显示404,也可能是我输入有误。 并不是接口废弃的原因,抱歉。

czy88840616 commented 1 year ago

快手上手文档增加数据模拟部分,避免地址错误请求失败的同时增加一个示例能力,脚手架已同步更新。

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

czy88840616 commented 10 months ago

@shad0whz 官网天气示例接口已经切换为自有地址。