저는 A 클래스의 fetch 메서드를 오버라이드하는 기본 클래스 A와 확장 클래스 B를가집니다. 그러나 B.fetch()를 호출하면 'baseclass'가 기록됩니다. 왜 B에 정의 된 메소드 정의를 호출하지 않습니까?타이프 스크립트 메서드 무시가 작동하지 않습니다.
class A {
protected apiPath: string = ''
static async fetch (id = null, Model = this, apiPath = this.apiPath): Promise<any> {
console.log('basefetch')
let url = apiPath
if(id) url += '/' + id
let { data } = await axios.get(url)
let item: any = new Model(data)
return item
}
}
class B extends A {
static async fetch(id = null, Model = this, apiPath = this.apiPath): Promise<Data> {
console.log('childfetch')
let {data} = await axios.get(apiPath)
if (typeof data.challenge.participating == 'undefined') {
data.challenge.participating = null
}
if (typeof data.challenge.progress == 'undefined') {
data.challenge.progress = null
}
return new Model(data)
}
class SomeOtherModule {
async doSomething() {
let b: B = await B.fetch()
}
}
당신이 클래스 B에서'fetch' 메소드를 호출하는 방법? 그 부분을 게시 할 수 있습니까? – Niladri
@Niladri 나는 그것을 추가했다 – Chris
@Chris'B.fetch()'는'Promise '를 반환하고'B' 타입의'b'에 할당 될 수 없다. 'apiPath'가 정적이 아니기 때문에 메서드 서명의'apiPath = this.apiPath'도 컴파일되지 않기 때문에 이것은 모두 의사 코드라고 가정합니다. 쇼가 자신의 행동을 나타내는 plunkr을 제공 할 수 있습니까? – zgue