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

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


 

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

  • 首先  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)
 );
}

 


參考app

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

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

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

相關文章
相關標籤/搜索