Skip to content

Commit

Permalink
AbstractMessageTransform#transformMessage(): improve return type. (co…
Browse files Browse the repository at this point in the history
…inbase#167)

This lets other packages use AbstractMessageTransform and have it
override transformMessage() and return null to avoid a tsc warning:

  Type 'null' is not assignable to type 'StreamMessage'.
  • Loading branch information
blair authored and fb55 committed Apr 10, 2018
1 parent f418a5f commit 6f6a23f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/core/ProductFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
***************************************************************************************************************************/

import { AbstractMessageTransform, MessageTransformConfig } from '../lib/AbstractMessageTransform';
import { StreamMessage } from '../core/Messages';

export interface ProductFilterConfig extends MessageTransformConfig {
productId: string;
Expand All @@ -29,8 +30,8 @@ export class ProductFilter extends AbstractMessageTransform {
this.productId = config.productId;
}

transformMessage(msg: any): any {
if (!msg || !msg.productId || msg.productId !== this.productId) {
transformMessage(msg: StreamMessage): StreamMessage {
if (!msg || !(msg as any).productId || (msg as any).productId !== this.productId) {
return null;
}
return msg;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/AbstractMessageTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export abstract class AbstractMessageTransform extends stream.Transform {

_transform(chunk: any, encoding: string, callback: (err: Error, chunk?: any) => void) {
if (typeof chunk === 'object' && isStreamMessage(chunk)) {
const msg: StreamMessage = chunk as StreamMessage;
const msg = chunk as StreamMessage;
const transformed = this.transformMessage(msg);
if (transformed) {
this.push(transformed);
Expand All @@ -56,5 +56,5 @@ export abstract class AbstractMessageTransform extends stream.Transform {
return callback(null, chunk);
}

abstract transformMessage(msg: StreamMessage): StreamMessage;
abstract transformMessage(msg: StreamMessage): null | StreamMessage;
}

0 comments on commit 6f6a23f

Please sign in to comment.