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

add ChaiHttp.Request to types #304

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

add ChaiHttp.Request to types #304

wants to merge 1 commit into from

Conversation

bgmort
Copy link

@bgmort bgmort commented Jan 20, 2023

Suppose I assign a type to an unresolved chai http request in Typescript. Chai doesn't export a type, so the type has to be imported from superagent, which breaks encapsulation. This PR exports a wrapper type so that requests can be typed without an explicit dependency on superagent.

Before:

import chai, { request } from 'chai'
import chaiHttp from 'chai-http'
import {SuperAgentRequest} from 'superagent' // breaks encapsulation

chai.use(chaiHttp)

let req: SuperAgentRequest
if (Math.random() < .5) {
	req = request('https://example.com').get('/')
}
else {
	req = request('https://other.com').get('/other')
}

req.set('Cookie', 'cookie=true')

After:

import chai, { request } from 'chai'
import chaiHttp from 'chai-http'

chai.use(chaiHttp)

let req: ChaiHttp.Request
if (Math.random() < .5) {
	req = request('https://example.com').get('/')
}
else {
	req = request('https://other.com').get('/other')
}

req.set('Cookie', 'cookie=true')

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

1 participant