Skip to content

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.

3 participants