Skip to content
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

Change never type to unknown #4142

Merged
merged 3 commits into from Oct 6, 2021

Conversation

remcohaszing
Copy link
Contributor

Using never was a workaround I introduced in 3002, because unknown wasn’t supperted by all relevant versions of TypeScript at the time. It is now, and it is much more correct.

caugner and others added 3 commits October 4, 2021 17:24
Using `never` was a workaround I introduced in 3002, because `unknown` wasn’t
supperted by all relevant versions of TypeScript at the time. It is now, and
it is much more correct.
@jasonsaayman jasonsaayman merged commit 6c00232 into axios:master Oct 6, 2021
@caugner
Copy link
Contributor

caugner commented Oct 6, 2021

Oh, my understanding was that introducing never was intended to force users to specify the type of the expected response data type. Isn't that no longer enforced when defaulting to unknown, or did I misinterpret the original intention?

@ImRodry
Copy link
Contributor

ImRodry commented Oct 7, 2021

That is still being enforced by this, it’s just a better but still stupid solution

@caugner
Copy link
Contributor

caugner commented Oct 7, 2021

@ImRodry Please have a look at the code of conduct and reconsider your wording.

Besides, could you please elaborate on why specifying the type might not always be desired when using axios in a TypeScript project, and possibly provide an example?

@remcohaszing
Copy link
Contributor Author

remcohaszing commented Oct 7, 2021

@caugner

Oh, my understanding was that introducing never was intended to force users to specify the type of the expected response data type. Isn't that no longer enforced when defaulting to unknown, or did I misinterpret the original intention?

That was exactly my goal, but using never was a hacky workaround I used at the time to make it work with TypeScript < 3.0, which was still somewhat relevant at the time. The correct type to use for unknown values is unknown.

You can see the difference by hovering over the values inside the if-statement blocks in this playground link

@ImRodry
Copy link
Contributor

ImRodry commented Oct 7, 2021

@ImRodry Please have a look at the code of conduct and reconsider your wording.

Besides, could you please elaborate on why specifying the type might not always be desired when using axios in a TypeScript project, and possibly provide an example?

Sure I’ll give you the exact example I’m working with
The mojang API has an endpoint where you can pass an IGN to obtain the user’s UUID. The resulting JSON object has 2 properties: name and id from which most of us only want the id since the name is what we pass. In my code I have a function that makes this request and only returns the id property, and I don’t need to make an interface for this because it’s simply useless. There are plenty of use cases like this out there, you shouldn’t limit people to what you want them to do.

@caugner
Copy link
Contributor

caugner commented Oct 7, 2021

@ImRodry What stops you from passing {id: string} as the generic type parameter (or any if you don't care about types at all)?

@ImRodry
Copy link
Contributor

ImRodry commented Oct 7, 2021

@ImRodry What stops you from passing {id: string} as the generic type parameter (or any if you don't care about types at all)?

Please stop suggesting any as I already explained the issue with that from a user’s side countless times
Ans yeah there’s nothing stopping me, the only issue is that it’s useless and annoying and doesn’t give me any advantage

@caugner
Copy link
Contributor

caugner commented Oct 7, 2021

@ImRodry I think we're not on the same page here, so I would suggest you to create an issue with a complete and more specific description of the problem you're having (including a code snippet). Besides, my advice would be to keep your wording friendly, if you actually want maintainers to invest their time in your issue. Maybe you're right, but calling a change you don't agree with "stupid" or "useless" will probably not get you what you want.

@ImRodry
Copy link
Contributor

ImRodry commented Oct 7, 2021

I have. Please see #4141

@axios axios locked as too heated and limited conversation to collaborators Oct 7, 2021
@remcohaszing remcohaszing deleted the unknown-return-type branch July 26, 2022 10:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants