Tuesday, March 9, 2021

JavaScript: TypeScript: This condition will always return 'true' since the types 'string' and 'EventEmitter' have no overlap.ts(2367)


 >PROBLEM


The code below returns the error message:

This condition will always return 'true' since the types 'string' and 'EventEmitter<string>' have no overlap.ts(2367)



*** BAD

  crossOffItem(event: EventEmitter<string>): void {

      const ritems = this.items.filter( it => it !== event);

      this.items = ritems;

  }




>SOLUTION


TypeScript complains that the types are not explicitly equivalent or comparable.


*** OK

  crossOffItem(event: EventEmitter<string>): void {

      const ritems = this.items.filter( it => it !== event.toString());

      this.items = ritems;

  }



POOR SOLUTION


  crossOffItem(event: EventEmitter<string>): void {

      const val = event.toString();

      const ritems = this.items.filter( it => it !== val);

      this.items = ritems;

  }


>ENV

Node.js v.14.15.4

No comments:

Post a Comment

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...