TS2339: property 'of' does not exist on type 'typeof Observable' - rxjs@6.2.2


【出現的問題】 TS2339: property 'of' does not exist on type 'typeof Observable' 


 

【解決方法】(如下代碼粉色標記)

  • 首先  import { of } from 'rxjs'; - 見下方【參考(1) 
  • 和 import {delay} from 'rxjs/operators'; - 見下方【參考(3) 
  • 然后將Observable.of() 改為 of() - 見下方【參考(1) 
  • 再然后在 delay 外邊加一層 pipe() - 見下方【參考(2) 
import {AbstractControl, FormControl, FormGroup} from '@angular/forms';
import {of} from 'rxjs';
import {delay} from 'rxjs/operators'; export
function mobileAsyncValidator (control: FormControl): any { var myreg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/; let valid = myreg.test(control.value); console.log('mobile的校驗結果是 - ' + valid); return of(valid ? null : {mobile: true}).pipe(
  delay(1000)
 );
}

 


參考

(1) https://stackoverflow.com/questions/38067580/property-of-does-not-exist-on-type-typeof-observable

(2) https://stackoverflow.com/questions/48826799/rxjs-observable-of-delay-is-not-a-function#answer-48826894

(3) https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM