Skip to content

Commit

Permalink
Migrate jest-get-type to TypeScript (jestjs#7818)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored and captain-yossarian committed Jul 18, 2019
1 parent 569018b commit e58335f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- `[*]`: Setup building, linting and testing of TypeScript ([#7808](https://github.com/facebook/jest/pull/7808))
- `[pretty-format]`: Migrate to TypeScript ([#7809](https://github.com/facebook/jest/pull/7809))
- `[diff-sequences]`: Migrate to Typescript ([#7820](https://github.com/facebook/jest/pull/7820))
- `[jest-get-type]`: Migrate to TypeScript ([#7818](https://github.com/facebook/jest/pull/7818))

### Performance

Expand Down
1 change: 1 addition & 0 deletions packages/jest-get-type/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
},
"license": "MIT",
"main": "build/index.js",
"types": "build/index.d.ts",
"gitHead": "634e5a54f46b2a62d1dc81a170562e6f4e55ad60"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
*
*/

'use strict';

const getType = require('..');
import getType from '..';

describe('.getType()', () => {
test('null', () => expect(getType(null)).toBe('null'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

'use strict';

export type ValueType =
type ValueType =
| 'array'
| 'boolean'
| 'function'
Expand All @@ -26,7 +22,7 @@ export type ValueType =

// get the type of a value with handling the edge cases like `typeof []`
// and `typeof null`
const getType = (value: any): ValueType => {
const getType = (value: unknown): ValueType => {
if (value === undefined) {
return 'undefined';
} else if (value === null) {
Expand All @@ -42,22 +38,23 @@ const getType = (value: any): ValueType => {
} else if (typeof value === 'string') {
return 'string';
} else if (typeof value === 'object') {
if (value.constructor === RegExp) {
return 'regexp';
} else if (value.constructor === Map) {
return 'map';
} else if (value.constructor === Set) {
return 'set';
} else if (value.constructor === Date) {
return 'date';
if (value != null) {
if (value.constructor === RegExp) {
return 'regexp';
} else if (value.constructor === Map) {
return 'map';
} else if (value.constructor === Set) {
return 'set';
} else if (value.constructor === Date) {
return 'date';
}
}
return 'object';
// $FlowFixMe https://github.com/facebook/flow/issues/1015
} else if (typeof value === 'symbol') {
return 'symbol';
}

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

module.exports = getType;
export = getType;
7 changes: 7 additions & 0 deletions packages/jest-get-type/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build"
}
}

0 comments on commit e58335f

Please sign in to comment.