Closed gucong3000 closed 6 years ago
function createPluginError(err: Error | string) {
return new PluginError(PLUGIN_NAME, err);
}
I don't know how to modify my code to compile
Thanks for PR, it was needed indeed. I proposed a change to better support custom errors, could you update your branch?
If you want to move on with the current types, just use an any
cast:
function createPluginError(err: Error | string) {
return new PluginError(PLUGIN_NAME, err as any);
}
Or you could do a disjunction on the type of err, but this looks a bit silly (it's better to use any
than get some convoluted code just to appease the type checker):
function createPluginError(err: Error | string) {
if (typeof err === "string") {
return new PluginError(PLUGIN_NAME, err);
} else {
return new PluginError(PLUGIN_NAME, err);
}
}
I thought that TS would automatically resolve the correct result but the fact that one of the variants has a generic parameter type or that there are different return values may have confused it. Adding the corresponding signature manually is the best solution for the moment.
https://travis-ci.org/jedmao/eclint/jobs/331685076