I have this:
export class XMLParser extends Transform {
constructor(opts?: XMLParserOpts, to?: TransformOptions) {
super(Object.assign({}, to || {}, {objectMode: true}));
}
}
basically I always need objectMode
to be true. However, what if the user passed in some weird value for to
? How can I check it to make sure the type is defined an object?
I can let the Transform class do its validation, but I'd rather do that manually and give a custom error message. But the problem is, I can't do this:
constructor(opts?: XMLParserOpts, to?: TransformOptions) {
if(to && typeof to !== 'object'){
throw new Error('no good bozo');
}
super(Object.assign({}, to || {}, {objectMode: true}));
}
how can do what I am looking for? (TS won't compile if super is not the first call in the constructor).