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

bigint printtype #125

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ type Factorize = {
(input: bigint): bigint[]
}

expectTypeOf<Factorize>().parameters.not.toEqualTypeOf<[number]>()
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[number] | [bigint]>()
expectTypeOf<Factorize>().returns.toEqualTypeOf<number[] | bigint[]>()

Expand Down
18 changes: 11 additions & 7 deletions src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ export type PrintType<T> =
? 'number'
: T extends number
? `literal number: ${T}`
: T extends null
? 'null'
: T extends undefined
? 'undefined'
: T extends (...args: any[]) => any
? 'function'
: '...'
: bigint extends T
? 'bigint'
: T extends bigint
? `literal bigint: ${T}`
: T extends null
? 'null'
: T extends undefined
? 'undefined'
: T extends (...args: any[]) => any
? 'function'
: '...'

/**
* Helper for showing end-user a hint why their type assertion is failing.
Expand Down
6 changes: 6 additions & 0 deletions test/__snapshots__/errors.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ test/usage.test.ts:999:999 - error TS2344: Type 'HasParam' does not satisfy the

999 expectTypeOf<NoParam>().toEqualTypeOf<HasParam>()
~~~~~~~~
test/usage.test.ts:999:999 - error TS2344: Type '[number]' does not satisfy the constraint '{ 0: "Expected: number, Actual: bigint"; }'.
Types of property '0' are incompatible.
Type 'number' is not assignable to type '"Expected: number, Actual: bigint"'.

999 expectTypeOf<Factorize>().parameters.toEqualTypeOf<[number]>()
~~~~~~~~
test/usage.test.ts:999:999 - error TS2349: This expression is not callable.
Type 'ExpectAny<(a: number) => number[]>' has no call signatures.

Expand Down
1 change: 1 addition & 0 deletions test/usage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ test('Up to ten overloads will produce union types for `.parameters` and `.retur
(input: bigint): bigint[]
}

expectTypeOf<Factorize>().parameters.not.toEqualTypeOf<[number]>()
expectTypeOf<Factorize>().parameters.toEqualTypeOf<[number] | [bigint]>()
expectTypeOf<Factorize>().returns.toEqualTypeOf<number[] | bigint[]>()

Expand Down