Skip to content

Commit 0c07df0

Browse files
authored
Migrate jest-get-type to TypeScript (#7818)
1 parent e8f5d62 commit 0c07df0

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- `[*]`: Setup building, linting and testing of TypeScript ([#7808](https://github.com/facebook/jest/pull/7808))
1010
- `[pretty-format]`: Migrate to TypeScript ([#7809](https://github.com/facebook/jest/pull/7809))
1111
- `[diff-sequences]`: Migrate to Typescript ([#7820](https://github.com/facebook/jest/pull/7820))
12+
- `[jest-get-type]`: Migrate to TypeScript ([#7818](https://github.com/facebook/jest/pull/7818))
1213

1314
### Performance
1415

packages/jest-get-type/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
},
1313
"license": "MIT",
1414
"main": "build/index.js",
15+
"types": "build/index.d.ts",
1516
"gitHead": "634e5a54f46b2a62d1dc81a170562e6f4e55ad60"
1617
}

packages/jest-get-type/src/__tests__/index.test.js renamed to packages/jest-get-type/src/__tests__/index.test.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
*
77
*/
88

9-
'use strict';
10-
11-
const getType = require('..');
9+
import getType from '..';
1210

1311
describe('.getType()', () => {
1412
test('null', () => expect(getType(null)).toBe('null'));

packages/jest-get-type/src/index.js renamed to packages/jest-get-type/src/index.ts

+13-16
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
6-
*
7-
* @flow
86
*/
97

10-
'use strict';
11-
12-
export type ValueType =
8+
type ValueType =
139
| 'array'
1410
| 'boolean'
1511
| 'function'
@@ -26,7 +22,7 @@ export type ValueType =
2622

2723
// get the type of a value with handling the edge cases like `typeof []`
2824
// and `typeof null`
29-
const getType = (value: any): ValueType => {
25+
const getType = (value: unknown): ValueType => {
3026
if (value === undefined) {
3127
return 'undefined';
3228
} else if (value === null) {
@@ -42,22 +38,23 @@ const getType = (value: any): ValueType => {
4238
} else if (typeof value === 'string') {
4339
return 'string';
4440
} else if (typeof value === 'object') {
45-
if (value.constructor === RegExp) {
46-
return 'regexp';
47-
} else if (value.constructor === Map) {
48-
return 'map';
49-
} else if (value.constructor === Set) {
50-
return 'set';
51-
} else if (value.constructor === Date) {
52-
return 'date';
41+
if (value != null) {
42+
if (value.constructor === RegExp) {
43+
return 'regexp';
44+
} else if (value.constructor === Map) {
45+
return 'map';
46+
} else if (value.constructor === Set) {
47+
return 'set';
48+
} else if (value.constructor === Date) {
49+
return 'date';
50+
}
5351
}
5452
return 'object';
55-
// $FlowFixMe https://github.com/facebook/flow/issues/1015
5653
} else if (typeof value === 'symbol') {
5754
return 'symbol';
5855
}
5956

6057
throw new Error(`value of unknown type: ${value}`);
6158
};
6259

63-
module.exports = getType;
60+
export = getType;

packages/jest-get-type/tsconfig.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "src",
5+
"outDir": "build"
6+
}
7+
}

0 commit comments

Comments
 (0)