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
HTTPError type is not exported #237
Comments
How is it inconvenient? |
I described the rationale for this change in issue #205 and implemented it in PR #205. I highly recommend reading those. Among other things, this was motivated by the desire to avoid having |
I also prefer ky.stop instead of named export. I don't question the rationale behind it. Following TypeScript code using 0.13 import * as ky from 'ky';
function logStatus(httpError: ky.HTTPError) {
console.log(httpError.response.status);
} Looks like this in 0.17 import ky from 'ky';
function logStatus(httpError: InstanceType<typeof ky.HTTPError>) {
console.log(httpError.response.status);
} Certainly, "inconvenient" is subjective. I'm sorry for that. Let me rephrase. I'll give it a shot in a PR I'll note the general idea here. Trivial example TypeScript class HTTPError extends Error {}
const ky = () => {};
ky.HTTPError = HTTPError;
export default ky; Produces following .d.ts (TS Playground v2 rocks) declare class HTTPError extends Error {
}
declare const ky: {
(): void;
HTTPError: typeof HTTPError;
};
export default ky; Exactly the current state of affairs :( However if I add type _HTTPError = HTTPError;
namespace ky {
export type HTTPError = _HTTPError;
} or namespace ky {
export type HTTPError = InstanceType<typeof ky.HTTPError>;
}
Since ky's .d.ts is maintained separately, my plan is to add this |
Problem
In 0.13, we could
import { HTTPError } from 'ky'
in TypeScript.In 0.17 the value is accessible as
ky.HTTPError
, but the type isInstanceType<typeof ky.HTTPError>
, what's a bit inconvenient.Possible solution
Instead of
declare const ky
there could be anamespace ky
inindex.d.ts
. Namespaces can contain types.The text was updated successfully, but these errors were encountered: