Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Change never type to unknown#4142

Merged
jasonsaayman merged 3 commits into
axios:masterfrom
remcohaszing:unknown-return-type
Oct 6, 2021
Merged

Change never type to unknown#4142
jasonsaayman merged 3 commits into
axios:masterfrom
remcohaszing:unknown-return-type

Conversation

@remcohaszing

Copy link
Copy Markdown
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

caugner commented Oct 6, 2021

Copy link
Copy Markdown
Contributor

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

ImRodry commented Oct 7, 2021

Copy link
Copy Markdown
Contributor

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

@caugner

caugner commented Oct 7, 2021

Copy link
Copy Markdown
Contributor

@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

remcohaszing commented Oct 7, 2021

Copy link
Copy Markdown
Contributor Author

@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

ImRodry commented Oct 7, 2021

Copy link
Copy Markdown
Contributor

@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

caugner commented Oct 7, 2021

Copy link
Copy Markdown
Contributor

@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

ImRodry commented Oct 7, 2021

Copy link
Copy Markdown
Contributor

@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

caugner commented Oct 7, 2021

Copy link
Copy Markdown
Contributor

@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

ImRodry commented Oct 7, 2021

Copy link
Copy Markdown
Contributor

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.

4 participants