Navigation Menu

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

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

@remcohaszing
Copy link
Contributor Author

@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.

Copy link
Contributor

@TimWolla TimWolla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants