[英]Property “somemethod” does not exist on type 'typeof “className”
I am getting a "Property 'searchStaff' does not exist on type 'typeof UserService'." 我收到“类型'UserService'上不存在属性'searchStaff'。” error in my editor when I try to use this api service class.
当我尝试使用此api服务类时,在编辑器中出现错误。 PS.
PS。 I am new to typescript.
我是打字稿新手。
import axios from "axios";
import { Observable } from "rxjs";
class UserService {
public searchStaff(): Observable<any> {
return Observable.fromPromise(axios.get("./staffs/search"));
}
}
export default new UserService();
I am trying to get data from this class. 我正在尝试从此类课程中获取数据。
const result = UserService.searchStaff();
You can directly put export
or export default
in your declaration. 您可以在声明中直接放置
export
或export default
。 So you can do: 因此,您可以执行以下操作:
export class UserService {
} }
or 要么
export default class UserService {
} }
You can find the different methods of using modules for typescript here . 您可以在此处找到使用模块作为打字稿的不同方法。
Also, looking at this line of code, const result = UserService.searchStaff();
同样,看这行代码,
const result = UserService.searchStaff();
are you instantiating UserService? 您要实例化UserService吗? If not, then you have to declare
searchStaff
as static
. 如果不是,则必须将
searchStaff
声明为static
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.