-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript compile error #10
Comments
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 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 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. |
This commit updates the signature of the `PluginError` constructor to loosen the constraints on the parameters in order to support union types while keeping inference on custom properties. This allows for example to use the pattern below: ``` function createPluginError(error: Error | string) { return new PluginError("test", error); } ``` (The tests were updated with more complex cases) See the discussions in gulpjs#10 and gulpjs#11 for details. - Closes gulpjs#10 - Closes gulpjs#11 /cc @gucong3000
This commit updates the signature of the `PluginError` constructor to loosen the constraints on the parameters in order to support union types while keeping inference on custom properties. This allows for example to use the pattern below: ``` function createPluginError(error: Error | string) { return new PluginError("test", error); } ``` (The tests were updated with more complex cases) See the discussions in gulpjs#10 and gulpjs#11 for details. - Closes gulpjs#10 - Closes gulpjs#11 /cc @gucong3000
This commit updates the signature of the `PluginError` constructor to loosen the constraints on the parameters in order to support union types while keeping inference on custom properties. This is a semver minor update (fix). This allows for example to use the pattern below: ``` function createPluginError(error: Error | string) { return new PluginError("test", error); } ``` (The tests were updated with more complex cases) See the discussions in gulpjs#10 and gulpjs#11 for details. - Closes gulpjs#10 - Closes gulpjs#11 /cc @gucong3000
This commit updates the signature of the `PluginError` constructor to loosen the constraints on the parameters in order to support union types while keeping inference on custom properties. This is a semver minor update (fix). This allows for example to use the pattern below: ``` function createPluginError(error: Error | string) { return new PluginError("test", error); } ``` (The tests were updated with more complex cases) See the discussions in gulpjs#10 and gulpjs#11 for details. - Closes gulpjs#10 - Closes gulpjs#11 /cc @gucong3000
This commit updates the signature of the `PluginError` constructor to loosen the constraints on the parameters in order to support union types while keeping inference on custom properties. This is a semver minor update (fix). This allows for example to use the pattern below: ``` function createPluginError(error: Error | string) { return new PluginError("test", error); } ``` (The tests were updated with more complex cases) See the discussions in #10 and #11 for details. - Closes #10 - Closes #11 /cc @gucong3000
https://travis-ci.org/jedmao/eclint/jobs/331685076
The text was updated successfully, but these errors were encountered: