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

expectType Generic Discussion Opener #163

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tommy-mitchell
Copy link
Contributor

From #142:

expectType doesn't work properly with generic functions. Here's a repro:

import {expectType} from 'tsd'

declare const inferrable: <T = 'SomeDefaultValue'>() => T

expectType<number>(inferrable()) // passes, should fail

I'm not sure if it's possible to fix given the API design, but here's the same test using expect-type which fails as it should.

import {expectTypeOf} from 'expect-type'

declare const inferrable: <T = 'SomeDefaultValue'>() => T

expectTypeOf(inferrable()).toEqualTypeOf<number>() // fails as expected, because `inferrable()` returns type `'SomeDefaultValue'`

Adds a reproduction test case:

// expect-error/generic/index.d.ts

export const inferrable: <T = 'SomeDefaultValue'>() => T;
// expect-error/generic/index.test-d.ts

expectError(expectType<number>(inferrable<true>())); // fails
expectError(expectType<number>(inferrable())); // should fail, doesn't

@skarab42
Copy link
Contributor

FI: This test pass with the new API proposal #168

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

2 participants