Skip to content

Commit

Permalink
Update comparison methods to support BigInt
Browse files Browse the repository at this point in the history
As per jestjs/jest#8382

TypeScript 3.2+ supports BigInt with esnext target.
TypeScript 3.8+ supports it with es2020 target.

dtslint is very particular on how the `typesVersions`
should be handled, hence the code duplication.
  • Loading branch information
D4nte committed May 4, 2020
1 parent cc1de99 commit cdfbf3a
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 0 deletions.
5 changes: 5 additions & 0 deletions types/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"dependencies": {
"jest-diff": "^25.2.1",
"pretty-format": "^25.2.1"
},
"types": "index",
"typesVersions": {
">=3.8.0-0": { "*": ["ts3.8/*"] },
">=3.2.0-0": { "*": ["ts3.2/*"] }
}
}
23 changes: 23 additions & 0 deletions types/jest/ts3.2/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// tslint:disable-next-line:no-bad-reference
/// <reference path="../index.d.ts" />

declare namespace jest {
interface Matchers<R, T = {}> {
/**
* For comparing numbers or big integer values.
*/
toBeGreaterThan(expected: number | bigint): R;
/**
* For comparing numbers or big integer values.
*/
toBeGreaterThanOrEqual(expected: number | bigint): R;
/**
* For comparing numbers or big integer values.
*/
toBeLessThan(expected: number | bigint): R;
/**
* For comparing numbers or big integer values.
*/
toBeLessThanOrEqual(expected: number | bigint): R;
}
}
13 changes: 13 additions & 0 deletions types/jest/ts3.2/jest-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* Basic matchers */

describe('', () => {
it('', () => {
expect(BigInt(0)).toBeGreaterThan(BigInt(1));

expect(BigInt(0)).toBeGreaterThanOrEqual(BigInt(1));

expect(BigInt(0)).toBeLessThan(BigInt(1));

expect(BigInt(0)).toBeLessThanOrEqual(BigInt(1));
});
});
20 changes: 20 additions & 0 deletions types/jest/ts3.2/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["dom", "es6", "esnext", "es2020"],
"noImplicitAny": true,
"noImplicitThis": false,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../../",
"typeRoots": ["../../"],
"target": "esnext",
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"jest-tests.ts"
]
}
6 changes: 6 additions & 0 deletions types/jest/ts3.2/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "dtslint/dt.json",
"rules": {
"no-unnecessary-generics": false
}
}
2 changes: 2 additions & 0 deletions types/jest/ts3.8/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// tslint:disable-next-line:no-bad-reference
/// <reference path="../ts3.2/index.d.ts" />
13 changes: 13 additions & 0 deletions types/jest/ts3.8/jest-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* Basic matchers */

describe('', () => {
it('', () => {
expect(0n).toBeGreaterThan(1n);

expect(0n).toBeGreaterThanOrEqual(1n);

expect(0n).toBeLessThan(1n);

expect(0n).toBeLessThanOrEqual(1n);
});
});
20 changes: 20 additions & 0 deletions types/jest/ts3.8/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["dom", "es6", "esnext", "es2020"],
"noImplicitAny": true,
"noImplicitThis": false,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../../",
"typeRoots": ["../../"],
"target": "es2020",
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"jest-tests.ts"
]
}
6 changes: 6 additions & 0 deletions types/jest/ts3.8/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "dtslint/dt.json",
"rules": {
"no-unnecessary-generics": false
}
}

0 comments on commit cdfbf3a

Please sign in to comment.