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 headers type to string record #3021

Merged
merged 2 commits into from Sep 5, 2021

Conversation

@remcohaszing
Copy link
Contributor

@remcohaszing remcohaszing commented Jun 13, 2020

This correctly reflects the type in a more type safe manner.

@remcohaszing
Copy link
Contributor Author

@remcohaszing remcohaszing commented Oct 27, 2020

@jasonsaayman Could you also have a look at this please? 😃

I’m also tagging @TimWolla because of their involvement in #2797

This forces TypeScript users to use objects whose values are strings as headers. I.e., currently the following is allowed:

import axios from 'axios';

axios.post('', {}, { headers: 'Invalid' })
axios.post('', {}, { headers: 13 })
axios.post('', {}, { headers: [] })
axios.post('', {}, { headers: { authorization: [] } })
// etc…

This changes the types, so only proper authorization headers are allowed, and the response header types are correct as well.

import axios from 'axios';

axios.post('', {}, { headers: { authorization: 'A string :)' } })

I don’t consider this to be a breaking change, as it still works the same for proper usage.

Loading

Copy link
Contributor

@TimWolla TimWolla left a comment

TIL about the Record type.

I don’t consider this to be a breaking change, as it still works the same for proper usage.

This is technically a breaking change, but only in a regard that it will find an actual bug in a consumer's code. TypeScript users will certainly appreciate the increased strictness in typing.

Loading

This correctly reflects the type in a more type safe manner.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants