-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix: unable to evaluate instanceof AjaxError
#6275
Conversation
Ignore that. I'd expected this to remove the |
Mhh now I see that although it does fix the instanceof issue, TS guards fail:
I'll try to give it a bit more thought see if I can keep both (i.e. internal on types, while being able to use typescript guards), otherwise I'll just remove the @internal annotation. |
by the way, |
Yeah, you're right. It's only the |
3ede978
to
fb6e5a3
Compare
I just changed to the simple "remove I did find a solution that would work, but doesn't feel right export interface AjaxErrorCtor {
/**
* Internal use only. Do not manually create instances of this type.
*/
new (internal: never): AjaxError
/**
* @internal
*/
new (message: string, xhr: XMLHttpRequest, request: AjaxRequest): AjaxError;
} And guards work fine. But I don't fully like it.... also when using it within |
That's fine. There are a whole bunch of other |
Why would people need to create their own |
To be clear: I'm not blocking this PR. I'm just saying I'm not sure we want to expose the ability to create new AjaxErrors, and I'm totally willing to change my mind. |
Nevermind, I need to learn to read more thoroughly:
|
Isn't this a possible solution for both problems ?
|
That's great to know, and yes, I think it would work now. For what it's worth, this was added to typescript less than a year ago microsoft/TypeScript#55052, and this issue was raised and PR opened more than 3 years ago. |
Description:
Because the constructor signature of
AjaxErrorCtor
andAjaxTimeoutErrorCtor
are marked as @internal, and #6215 addedstripInternals: true
, the interface of these two constructors was exported as an empty interface.Typescript would then complain on projects that use
error instanceof AjaxError
, as it doesn't identify AjaxError as callable.Related issue (if exists): #6269
I've found this solution, which I think works nicely: The type is still exported, the constructor signature is still stripped (because it's internal) and typescript now allows to check instanceof AjaxError, while preventing the consumer from trying to call the constructor: