File tree 5 files changed +23
-19
lines changed
5 files changed +23
-19
lines changed Original file line number Diff line number Diff line change 9
9
- ` [*] ` : Setup building, linting and testing of TypeScript ([ #7808 ] ( https://github.com/facebook/jest/pull/7808 ) )
10
10
- ` [pretty-format] ` : Migrate to TypeScript ([ #7809 ] ( https://github.com/facebook/jest/pull/7809 ) )
11
11
- ` [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 ) )
12
13
13
14
### Performance
14
15
Original file line number Diff line number Diff line change 12
12
},
13
13
"license" : " MIT" ,
14
14
"main" : " build/index.js" ,
15
+ "types" : " build/index.d.ts" ,
15
16
"gitHead" : " 634e5a54f46b2a62d1dc81a170562e6f4e55ad60"
16
17
}
Original file line number Diff line number Diff line change 6
6
*
7
7
*/
8
8
9
- 'use strict' ;
10
-
11
- const getType = require ( '..' ) ;
9
+ import getType from '..' ;
12
10
13
11
describe ( '.getType()' , ( ) => {
14
12
test ( 'null' , ( ) => expect ( getType ( null ) ) . toBe ( 'null' ) ) ;
Original file line number Diff line number Diff line change 3
3
*
4
4
* This source code is licensed under the MIT license found in the
5
5
* LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow
8
6
*/
9
7
10
- 'use strict' ;
11
-
12
- export type ValueType =
8
+ type ValueType =
13
9
| 'array'
14
10
| 'boolean'
15
11
| 'function'
@@ -26,7 +22,7 @@ export type ValueType =
26
22
27
23
// get the type of a value with handling the edge cases like `typeof []`
28
24
// and `typeof null`
29
- const getType = ( value : any ) : ValueType => {
25
+ const getType = ( value : unknown ) : ValueType => {
30
26
if ( value === undefined ) {
31
27
return 'undefined' ;
32
28
} else if ( value === null ) {
@@ -42,22 +38,23 @@ const getType = (value: any): ValueType => {
42
38
} else if ( typeof value === 'string' ) {
43
39
return 'string' ;
44
40
} 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
+ }
53
51
}
54
52
return 'object' ;
55
- // $FlowFixMe https://github.com/facebook/flow/issues/1015
56
53
} else if ( typeof value === 'symbol' ) {
57
54
return 'symbol' ;
58
55
}
59
56
60
57
throw new Error ( `value of unknown type: ${ value } ` ) ;
61
58
} ;
62
59
63
- module . exports = getType ;
60
+ export = getType ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "extends" : " ../../tsconfig.json" ,
3
+ "compilerOptions" : {
4
+ "rootDir" : " src" ,
5
+ "outDir" : " build"
6
+ }
7
+ }
You can’t perform that action at this time.
0 commit comments