Home > Back-end >  ts Subject is not assignable to method's
ts Subject is not assignable to method's

Time:05-11

I am getting a build error message ts2684 'this' context of type 'Subject' is not assignable to method'. I am import Subject from rxjs and then creating a property onSentenceChangeDebouncer. In the constructor I am using this so I am not sure why I am getting the error is not assignable to method

Severity Code Description File Project Line Suppression State Error Build:The 'this' context of type 'Subject' is not assignable to method's 'this' of type 'Observable'. The type 'returns by lift(...) are incompatible between these types. Type 'Observable' is not assignable to type 'Observable'. Type 'void' is not assignable to type R.

Code

import { Subject } from "rxjs";

onSentenceChangeDebouncer: Subject<void> = new Subject<void>();


 constructor(
        this.onSentenceChangeDebouncer
            .debounceTime(300)
            .subscribe(() => {
                this.updateConceptDependencies();
                this.compileSentence();
            });

}

CodePudding user response:

you put your code on the wrong scope, u probably want to do it like this:

 constructor() {
 this.onSentenceChangeDebouncer
            .debounceTime(300)
            .subscribe(() => {
                this.updateConceptDependencies();
                this.compileSentence();
            });
}
    

CodePudding user response:

It looks like your constructor is missing this closing ')' your code should look something like this:

import { Subject } from "rxjs";


class SomeClass {
    onSentenceChangeDebouncer: Subject<void> = new Subject<void>();
    
    constructor() {
        this.onSentenceChangeDebouncer
            .debounceTime(300)
            .subscribe(() => {
            
            
               this.updateConceptDependencies();
               this.compileSentence();
            });

    }

    updateConceptDependencies() { /* some logic */ }
    compileSentence() { /* some logic */ }

}
  • Related