diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fd0b87aefb8..8d01ec2a25d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/jest-get-type/package.json b/packages/jest-get-type/package.json index 422b6d8f2ab8..2b055dd2d218 100644 --- a/packages/jest-get-type/package.json +++ b/packages/jest-get-type/package.json @@ -12,5 +12,6 @@ }, "license": "MIT", "main": "build/index.js", + "types": "build/index.d.ts", "gitHead": "634e5a54f46b2a62d1dc81a170562e6f4e55ad60" } diff --git a/packages/jest-get-type/src/__tests__/index.test.js b/packages/jest-get-type/src/__tests__/index.test.ts similarity index 95% rename from packages/jest-get-type/src/__tests__/index.test.js rename to packages/jest-get-type/src/__tests__/index.test.ts index 8390b9a4bfd6..8a34a0cb947d 100644 --- a/packages/jest-get-type/src/__tests__/index.test.js +++ b/packages/jest-get-type/src/__tests__/index.test.ts @@ -6,9 +6,7 @@ * */ -'use strict'; - -const getType = require('..'); +import getType from '..'; describe('.getType()', () => { test('null', () => expect(getType(null)).toBe('null')); diff --git a/packages/jest-get-type/src/index.js b/packages/jest-get-type/src/index.ts similarity index 71% rename from packages/jest-get-type/src/index.js rename to packages/jest-get-type/src/index.ts index 3a444dd6f84d..dd15b71be771 100644 --- a/packages/jest-get-type/src/index.js +++ b/packages/jest-get-type/src/index.ts @@ -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' @@ -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) { @@ -42,17 +38,18 @@ 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'; } @@ -60,4 +57,4 @@ const getType = (value: any): ValueType => { throw new Error(`value of unknown type: ${value}`); }; -module.exports = getType; +export = getType; diff --git a/packages/jest-get-type/tsconfig.json b/packages/jest-get-type/tsconfig.json new file mode 100644 index 000000000000..7bb06bce6d20 --- /dev/null +++ b/packages/jest-get-type/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + } +}