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

Migrate jest-get-type to TypeScript #7818

Merged
merged 4 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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))
- `[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"
}
}