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

Can't expect type on a type intersection #59

Closed
Ethan-Arrowood opened this issue Nov 22, 2019 · 3 comments
Closed

Can't expect type on a type intersection #59

Ethan-Arrowood opened this issue Nov 22, 2019 · 3 comments

Comments

@Ethan-Arrowood
Copy link
Contributor

Ethan-Arrowood commented Nov 22, 2019

I'm getting this error message from my unit test:

Parameter type HeadersType is declared too wide for argument type IncomingHttpHeaders & HeadersType.

I understand this has something to do with expectType being is strict mode (#40). Can you please share how I could improve my type check here? Should I use something other than void?

The type definition (simplified)

interface CustomHeaders<G> {
  headers: http.IncomingHttpHeaders & G
}

And my test implementation (simplified)

type HeadersType = { prop: string }
const req: CustomHeaders<HeadersType> = { headers: { prop: 'Header' } }
expectType<HeadersType>(obj.headers)

I made a typescript playground that implements this pattern so I don't know why its failing in TSD

@Ethan-Arrowood Ethan-Arrowood changed the title void too wide for Interface & void Can't expect type on a type intersection Nov 22, 2019
@Ethan-Arrowood
Copy link
Contributor Author

If you want to see the whole example / where I discovered this issue checkout the reference issue ^^ from the Fastify library

@ExE-Boss
Copy link

You need to call:

expectType<http.IncomingHttpHeaders & HeadersType>(obj.headers);

@Ethan-Arrowood
Copy link
Contributor Author

Thank you @ExE-Boss

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

No branches or pull requests

2 participants