flow-api-translator 0.36.0 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,6 +26,7 @@ import {
26
26
  unexpectedTranslationError as unexpectedTranslationErrorBase,
27
27
  } from './utils/ErrorUtils';
28
28
  import {removeAtFlowFromDocblock} from './utils/DocblockUtils';
29
+ import {extractPropertyKeyLiterals} from './utils/TSNodeUtils';
29
30
  import {EOL} from 'os';
30
31
 
31
32
  type DeclarationOrUnsupported<T> = T | TSESTree.TSTypeAliasDeclaration;
@@ -35,23 +36,23 @@ const DUMMY_LOC: FlowESTree.SourceLocation = {
35
36
  end: {line: 1, column: 0},
36
37
  };
37
38
 
38
- type LooseOmit<O: interface {}, K: $Keys<$FlowFixMe>> = Pick<
39
+ type LooseOmit<O extends interface {}, K extends keyof $FlowFixMe> = Pick<
39
40
  O,
40
- Exclude<$Keys<O>, K>,
41
+ Exclude<keyof O, K>,
41
42
  >;
42
- function constructFlowNode<T: FlowESTree.BaseNode>(
43
+ function constructFlowNode<T extends FlowESTree.BaseNode>(
43
44
  node: LooseOmit<NoInfer<T>, 'parent'>,
44
45
  ): T {
45
- return (node: $FlowFixMe);
46
+ return node as $FlowFixMe;
46
47
  }
47
48
 
48
49
  const cloneJSDocCommentsToNewNode =
49
50
  // $FlowExpectedError[incompatible-type] - trust me this re-type is 100% safe
50
- (cloneJSDocCommentsToNewNodeOriginal: (mixed, mixed) => void);
51
+ cloneJSDocCommentsToNewNodeOriginal as (unknown, unknown) => void;
51
52
 
52
53
  const makeCommentOwnLine =
53
54
  // $FlowExpectedError[incompatible-type] - trust me this re-type is 100% safe
54
- (makeCommentOwnLineOriginal: (string, mixed) => string);
55
+ makeCommentOwnLineOriginal as (string, unknown) => string;
55
56
 
56
57
  const VALID_REACT_IMPORTS = new Set<string>(['React', 'react']);
57
58
 
@@ -180,7 +181,7 @@ const getTransforms = (
180
181
  // $FlowExpectedError[cannot-write]
181
182
  node.comments ??= [];
182
183
  // $FlowExpectedError[incompatible-type]
183
- (node.comments: Array<TSESTree.Comment>).push(comment);
184
+ (node.comments as Array<TSESTree.Comment>).push(comment);
184
185
  }
185
186
  function unsupportedAnnotation(
186
187
  node: ObjectWithLoc,
@@ -385,12 +386,12 @@ const getTransforms = (
385
386
  loc: DUMMY_LOC,
386
387
  computed: false,
387
388
  id: transform.Identifier(member.id, false),
388
- initializer: ({
389
+ initializer: {
389
390
  type: 'Literal',
390
391
  loc: DUMMY_LOC,
391
392
  raw: `"${member.id.name}"`,
392
393
  value: member.id.name,
393
- }: TSESTree.StringLiteral),
394
+ } as TSESTree.StringLiteral,
394
395
  });
395
396
  break;
396
397
  }
@@ -607,7 +608,7 @@ const getTransforms = (
607
608
  loc: DUMMY_LOC,
608
609
  name: 'IterableIterator',
609
610
  },
610
- typeParameters: {
611
+ typeArguments: {
611
612
  type: 'TSTypeParameterInstantiation',
612
613
  loc: DUMMY_LOC,
613
614
  params: [
@@ -818,13 +819,13 @@ const getTransforms = (
818
819
  return {
819
820
  type: 'TSLiteralType',
820
821
  loc: DUMMY_LOC,
821
- literal: ({
822
+ literal: {
822
823
  type: 'Literal',
823
824
  loc: DUMMY_LOC,
824
825
  value: node.value,
825
826
  raw: node.raw,
826
827
  bigint,
827
- }: TSESTree.BigIntLiteral),
828
+ } as TSESTree.BigIntLiteral,
828
829
  };
829
830
  },
830
831
  BigIntTypeAnnotation(
@@ -849,12 +850,12 @@ const getTransforms = (
849
850
  return {
850
851
  type: 'TSLiteralType',
851
852
  loc: DUMMY_LOC,
852
- literal: ({
853
+ literal: {
853
854
  type: 'Literal',
854
855
  loc: DUMMY_LOC,
855
856
  value: node.value,
856
857
  raw: node.raw,
857
- }: TSESTree.BooleanLiteral),
858
+ } as TSESTree.BooleanLiteral,
858
859
  };
859
860
  },
860
861
  BooleanTypeAnnotation(
@@ -872,7 +873,7 @@ const getTransforms = (
872
873
  type: 'TSClassImplements',
873
874
  loc: DUMMY_LOC,
874
875
  expression: transform.Identifier(node.id, false),
875
- typeParameters: transform.TypeParameterInstantiation(
876
+ typeArguments: transform.TypeParameterInstantiation(
876
877
  node.typeParameters,
877
878
  ),
878
879
  };
@@ -1084,8 +1085,8 @@ const getTransforms = (
1084
1085
  ? null
1085
1086
  : superClass.id.type === 'QualifiedTypeIdentifier'
1086
1087
  ? transform.QualifiedTypeIdentifier(superClass.id)
1087
- : transform.Identifier((superClass.id: $FlowFixMe), false),
1088
- superTypeParameters: transform.TypeParameterInstantiation(
1088
+ : transform.Identifier(superClass.id as $FlowFixMe, false),
1089
+ superTypeArguments: transform.TypeParameterInstantiation(
1089
1090
  superClass?.typeParameters,
1090
1091
  ),
1091
1092
  typeParameters:
@@ -1378,7 +1379,7 @@ const getTransforms = (
1378
1379
  if (node.source === null) {
1379
1380
  // eslint-disable-next-line eqeqeq
1380
1381
  if (node.declaration === null) {
1381
- return ({
1382
+ return {
1382
1383
  type: 'ExportNamedDeclaration',
1383
1384
  loc: DUMMY_LOC,
1384
1385
  // flow does not currently support attributes
@@ -1388,7 +1389,7 @@ const getTransforms = (
1388
1389
  exportKind: 'value',
1389
1390
  source: null,
1390
1391
  specifiers: node.specifiers.map(transform.ExportSpecifier),
1391
- }: TSESTree.ExportNamedDeclarationWithoutSourceWithMultiple);
1392
+ } as TSESTree.ExportNamedDeclarationWithoutSourceWithMultiple;
1392
1393
  }
1393
1394
 
1394
1395
  const declarations = ((): Array<{
@@ -1537,7 +1538,7 @@ const getTransforms = (
1537
1538
 
1538
1539
  return mappedDeclarations.flat();
1539
1540
  } else {
1540
- return ({
1541
+ return {
1541
1542
  type: 'ExportNamedDeclaration',
1542
1543
  loc: DUMMY_LOC,
1543
1544
  // flow does not currently support attributes
@@ -1547,7 +1548,7 @@ const getTransforms = (
1547
1548
  exportKind: 'value',
1548
1549
  source: transform.StringLiteral(node.source),
1549
1550
  specifiers: node.specifiers.map(transform.ExportSpecifier),
1550
- }: TSESTree.ExportNamedDeclarationWithSource);
1551
+ } as TSESTree.ExportNamedDeclarationWithSource;
1551
1552
  }
1552
1553
  }
1553
1554
  },
@@ -1582,7 +1583,7 @@ const getTransforms = (
1582
1583
  name: `ReactNode`,
1583
1584
  },
1584
1585
  },
1585
- typeParameters: undefined,
1586
+ typeArguments: undefined,
1586
1587
  },
1587
1588
  };
1588
1589
 
@@ -1605,9 +1606,9 @@ const getTransforms = (
1605
1606
  };
1606
1607
  },
1607
1608
  ComponentTypeParameters(
1608
- params: $ReadOnlyArray<FlowESTree.ComponentTypeParameter>,
1609
+ params: ReadonlyArray<FlowESTree.ComponentTypeParameter>,
1609
1610
  rest: FlowESTree.ComponentTypeParameter | null,
1610
- ): $ReadOnlyArray<TSESTree.Parameter> {
1611
+ ): ReadonlyArray<TSESTree.Parameter> {
1611
1612
  if (params.length === 0 && rest != null) {
1612
1613
  return [
1613
1614
  {
@@ -1974,7 +1975,7 @@ const getTransforms = (
1974
1975
  })();
1975
1976
 
1976
1977
  const mainExport = {
1977
- type: ('ExportNamedDeclaration': 'ExportNamedDeclaration'),
1978
+ type: 'ExportNamedDeclaration' as 'ExportNamedDeclaration',
1978
1979
  loc: DUMMY_LOC,
1979
1980
  assertions: [],
1980
1981
  declaration: exportedDeclaration,
@@ -2112,7 +2113,7 @@ const getTransforms = (
2112
2113
 
2113
2114
  const assertHasExactlyNTypeParameters = (
2114
2115
  count: number,
2115
- ): $ReadOnlyArray<TSESTree.TypeNode> => {
2116
+ ): ReadonlyArray<TSESTree.TypeNode> => {
2116
2117
  if (node.typeParameters != null) {
2117
2118
  if (node.typeParameters.params.length !== count) {
2118
2119
  throw translationError(
@@ -2143,7 +2144,7 @@ const getTransforms = (
2143
2144
  function assertHasTypeParametersInRange(
2144
2145
  min: number,
2145
2146
  max: number,
2146
- ): $ReadOnlyArray<TSESTree.TypeNode> {
2147
+ ): ReadonlyArray<TSESTree.TypeNode> {
2147
2148
  const {typeParameters} = node;
2148
2149
  if (typeParameters == null) {
2149
2150
  if (min > 0) {
@@ -2219,7 +2220,7 @@ const getTransforms = (
2219
2220
  loc: DUMMY_LOC,
2220
2221
  name: 'ArrayLike',
2221
2222
  },
2222
- typeParameters: {
2223
+ typeArguments: {
2223
2224
  type: 'TSTypeParameterInstantiation',
2224
2225
  loc: DUMMY_LOC,
2225
2226
  params: assertHasExactlyNTypeParameters(1),
@@ -2239,7 +2240,7 @@ const getTransforms = (
2239
2240
  loc: DUMMY_LOC,
2240
2241
  name: 'Pick',
2241
2242
  },
2242
- typeParameters: {
2243
+ typeArguments: {
2243
2244
  type: 'TSTypeParameterInstantiation',
2244
2245
  loc: DUMMY_LOC,
2245
2246
  params: [
@@ -2252,7 +2253,7 @@ const getTransforms = (
2252
2253
  loc: DUMMY_LOC,
2253
2254
  name: 'Exclude',
2254
2255
  },
2255
- typeParameters: {
2256
+ typeArguments: {
2256
2257
  type: 'TSTypeParameterInstantiation',
2257
2258
  loc: DUMMY_LOC,
2258
2259
  params: [
@@ -2309,7 +2310,7 @@ const getTransforms = (
2309
2310
  }
2310
2311
 
2311
2312
  // New AST format for `typeof import('module')`
2312
- return ({
2313
+ return {
2313
2314
  type: 'TSTypeQuery',
2314
2315
  loc: DUMMY_LOC,
2315
2316
  exprName: {
@@ -2317,9 +2318,11 @@ const getTransforms = (
2317
2318
  loc: DUMMY_LOC,
2318
2319
  argument: moduleName,
2319
2320
  qualifier: null,
2320
- typeParameters: null,
2321
+ options: null,
2322
+ source: moduleName.literal,
2323
+ typeArguments: null,
2321
2324
  },
2322
- }: $FlowFixMe);
2325
+ } as $FlowFixMe;
2323
2326
  }
2324
2327
 
2325
2328
  case '$FlowFixMe': {
@@ -2397,7 +2400,7 @@ const getTransforms = (
2397
2400
  loc: DUMMY_LOC,
2398
2401
  name: 'NonNullable',
2399
2402
  },
2400
- typeParameters: {
2403
+ typeArguments: {
2401
2404
  type: 'TSTypeParameterInstantiation',
2402
2405
  loc: DUMMY_LOC,
2403
2406
  params: assertHasExactlyNTypeParameters(1),
@@ -2415,7 +2418,7 @@ const getTransforms = (
2415
2418
  loc: DUMMY_LOC,
2416
2419
  name: 'Readonly',
2417
2420
  },
2418
- typeParameters: {
2421
+ typeArguments: {
2419
2422
  type: 'TSTypeParameterInstantiation',
2420
2423
  loc: DUMMY_LOC,
2421
2424
  params: assertHasExactlyNTypeParameters(1),
@@ -2436,7 +2439,7 @@ const getTransforms = (
2436
2439
  loc: DUMMY_LOC,
2437
2440
  name: 'ReadonlyArray',
2438
2441
  },
2439
- typeParameters: {
2442
+ typeArguments: {
2440
2443
  type: 'TSTypeParameterInstantiation',
2441
2444
  loc: DUMMY_LOC,
2442
2445
  params: assertHasExactlyNTypeParameters(1),
@@ -2453,7 +2456,7 @@ const getTransforms = (
2453
2456
  loc: DUMMY_LOC,
2454
2457
  name: 'ReadonlyMap',
2455
2458
  },
2456
- typeParameters: {
2459
+ typeArguments: {
2457
2460
  type: 'TSTypeParameterInstantiation',
2458
2461
  loc: DUMMY_LOC,
2459
2462
  params: assertHasExactlyNTypeParameters(2),
@@ -2470,7 +2473,7 @@ const getTransforms = (
2470
2473
  loc: DUMMY_LOC,
2471
2474
  name: 'ReadonlySet',
2472
2475
  },
2473
- typeParameters: {
2476
+ typeArguments: {
2474
2477
  type: 'TSTypeParameterInstantiation',
2475
2478
  loc: DUMMY_LOC,
2476
2479
  params: assertHasExactlyNTypeParameters(1),
@@ -2640,7 +2643,7 @@ const getTransforms = (
2640
2643
  const hasReactImport = isReactImport(baseId, baseId.name);
2641
2644
  if (validReactImportOrGlobal || hasReactImport) {
2642
2645
  switch (fullTypeName) {
2643
- // TODO: In flow this is `ChildrenArray<T> = T | $ReadOnlyArray<ChildrenArray<T>>`.
2646
+ // TODO: In flow this is `ChildrenArray<T> = T | ReadonlyArray<ChildrenArray<T>>`.
2644
2647
  // The recursive nature of it is rarely needed, so we're simplifying this for now
2645
2648
  // but omitting that aspect. Once we're able to provide utility types for our translations,
2646
2649
  // we should update this.
@@ -2662,7 +2665,7 @@ const getTransforms = (
2662
2665
  loc: DUMMY_LOC,
2663
2666
  name: 'ReadonlyArray',
2664
2667
  },
2665
- typeParameters: {
2668
+ typeArguments: {
2666
2669
  type: 'TSTypeParameterInstantiation',
2667
2670
  loc: DUMMY_LOC,
2668
2671
  params: [param],
@@ -2703,7 +2706,7 @@ const getTransforms = (
2703
2706
  name: 'Component',
2704
2707
  },
2705
2708
  },
2706
- typeParameters: {
2709
+ typeArguments: {
2707
2710
  type: 'TSTypeParameterInstantiation',
2708
2711
  loc: DUMMY_LOC,
2709
2712
  params: params.map(param => transformTypeAnnotationType(param)),
@@ -2728,7 +2731,7 @@ const getTransforms = (
2728
2731
  name: `Context`,
2729
2732
  },
2730
2733
  },
2731
- typeParameters: {
2734
+ typeArguments: {
2732
2735
  type: 'TSTypeParameterInstantiation',
2733
2736
  loc: DUMMY_LOC,
2734
2737
  params: assertHasExactlyNTypeParameters(1),
@@ -2771,7 +2774,7 @@ const getTransforms = (
2771
2774
  name: `ElementType`,
2772
2775
  },
2773
2776
  },
2774
- typeParameters: undefined,
2777
+ typeArguments: undefined,
2775
2778
  };
2776
2779
  }
2777
2780
  // React.Node -> React.ReactNode
@@ -2791,7 +2794,7 @@ const getTransforms = (
2791
2794
  name: `ReactNode`,
2792
2795
  },
2793
2796
  },
2794
- typeParameters: undefined,
2797
+ typeArguments: undefined,
2795
2798
  };
2796
2799
  }
2797
2800
  // React.Element<typeof Component> -> React.ReactElement<typeof Component>
@@ -2810,7 +2813,7 @@ const getTransforms = (
2810
2813
  name: `ReactElement`,
2811
2814
  },
2812
2815
  },
2813
- typeParameters: {
2816
+ typeArguments: {
2814
2817
  type: 'TSTypeParameterInstantiation',
2815
2818
  loc: DUMMY_LOC,
2816
2819
  params: assertHasExactlyNTypeParameters(1),
@@ -2834,7 +2837,7 @@ const getTransforms = (
2834
2837
  name: `ComponentRef`,
2835
2838
  },
2836
2839
  },
2837
- typeParameters: {
2840
+ typeArguments: {
2838
2841
  type: 'TSTypeParameterInstantiation',
2839
2842
  loc: DUMMY_LOC,
2840
2843
  params: assertHasExactlyNTypeParameters(1),
@@ -2889,7 +2892,7 @@ const getTransforms = (
2889
2892
  name: 'Element',
2890
2893
  },
2891
2894
  },
2892
- typeParameters: undefined,
2895
+ typeArguments: undefined,
2893
2896
  };
2894
2897
  }
2895
2898
  // React.ComponentType<Config> -> React.ComponentType<Config>
@@ -2909,7 +2912,7 @@ const getTransforms = (
2909
2912
  name: 'ComponentType',
2910
2913
  },
2911
2914
  },
2912
- typeParameters: {
2915
+ typeArguments: {
2913
2916
  type: 'TSTypeParameterInstantiation',
2914
2917
  loc: DUMMY_LOC,
2915
2918
  params: assertHasExactlyNTypeParameters(1),
@@ -2937,7 +2940,7 @@ const getTransforms = (
2937
2940
  );
2938
2941
  }
2939
2942
 
2940
- const newParams = ((): $ReadOnlyArray<TSESTree.TypeNode> => {
2943
+ const newParams = ((): ReadonlyArray<TSESTree.TypeNode> => {
2941
2944
  if (params.length === 1) {
2942
2945
  return assertHasExactlyNTypeParameters(1);
2943
2946
  }
@@ -2968,7 +2971,7 @@ const getTransforms = (
2968
2971
  name: 'RefAttributes',
2969
2972
  },
2970
2973
  },
2971
- typeParameters: {
2974
+ typeArguments: {
2972
2975
  type: 'TSTypeParameterInstantiation',
2973
2976
  loc: DUMMY_LOC,
2974
2977
  params: [ref],
@@ -2992,7 +2995,7 @@ const getTransforms = (
2992
2995
  name: 'ComponentType',
2993
2996
  },
2994
2997
  },
2995
- typeParameters: {
2998
+ typeArguments: {
2996
2999
  type: 'TSTypeParameterInstantiation',
2997
3000
  loc: DUMMY_LOC,
2998
3001
  params: newParams,
@@ -3016,7 +3019,7 @@ const getTransforms = (
3016
3019
  name: 'ComponentProps',
3017
3020
  },
3018
3021
  },
3019
- typeParameters: {
3022
+ typeArguments: {
3020
3023
  type: 'TSTypeParameterInstantiation',
3021
3024
  loc: DUMMY_LOC,
3022
3025
  params: assertHasExactlyNTypeParameters(1),
@@ -3054,7 +3057,7 @@ const getTransforms = (
3054
3057
  name: 'LibraryManagedAttributes',
3055
3058
  },
3056
3059
  },
3057
- typeParameters: {
3060
+ typeArguments: {
3058
3061
  type: 'TSTypeParameterInstantiation',
3059
3062
  loc: DUMMY_LOC,
3060
3063
  params: [
@@ -3072,7 +3075,7 @@ const getTransforms = (
3072
3075
  name: `ComponentProps`,
3073
3076
  },
3074
3077
  },
3075
- typeParameters: {
3078
+ typeArguments: {
3076
3079
  type: 'TSTypeParameterInstantiation',
3077
3080
  loc: DUMMY_LOC,
3078
3081
  params: [param],
@@ -3099,7 +3102,7 @@ const getTransforms = (
3099
3102
  name: 'Ref',
3100
3103
  },
3101
3104
  },
3102
- typeParameters: {
3105
+ typeArguments: {
3103
3106
  type: 'TSTypeParameterInstantiation',
3104
3107
  loc: DUMMY_LOC,
3105
3108
  params: assertHasExactlyNTypeParameters(1),
@@ -3117,7 +3120,7 @@ const getTransforms = (
3117
3120
  node.id.type === 'Identifier'
3118
3121
  ? transform.Identifier(node.id, false)
3119
3122
  : transform.QualifiedTypeIdentifier(node.id),
3120
- typeParameters: transform.TypeParameterInstantiation(
3123
+ typeArguments: transform.TypeParameterInstantiation(
3121
3124
  node.typeParameters,
3122
3125
  ),
3123
3126
  };
@@ -3256,7 +3259,7 @@ const getTransforms = (
3256
3259
  node.id.type === 'QualifiedTypeIdentifier'
3257
3260
  ? transform.QualifiedTypeIdentifier(node.id)
3258
3261
  : transform.Identifier(node.id, false),
3259
- typeParameters: transform.TypeParameterInstantiation(
3262
+ typeArguments: transform.TypeParameterInstantiation(
3260
3263
  node.typeParameters,
3261
3264
  ),
3262
3265
  };
@@ -3276,8 +3279,8 @@ const getTransforms = (
3276
3279
  type: 'TSTypeReference',
3277
3280
  loc: DUMMY_LOC,
3278
3281
  // Bug: ex.id can be qualified
3279
- typeName: transform.Identifier((ex.id: $FlowFixMe), false),
3280
- typeParameters: transform.TypeParameterInstantiation(
3282
+ typeName: transform.Identifier(ex.id as $FlowFixMe, false),
3283
+ typeArguments: transform.TypeParameterInstantiation(
3281
3284
  ex.typeParameters,
3282
3285
  ),
3283
3286
  })),
@@ -3364,12 +3367,12 @@ const getTransforms = (
3364
3367
  return {
3365
3368
  type: 'TSLiteralType',
3366
3369
  loc: DUMMY_LOC,
3367
- literal: ({
3370
+ literal: {
3368
3371
  type: 'Literal',
3369
3372
  loc: DUMMY_LOC,
3370
3373
  value: node.value,
3371
3374
  raw: node.raw,
3372
- }: TSESTree.NumberLiteral),
3375
+ } as TSESTree.NumberLiteral,
3373
3376
  };
3374
3377
  },
3375
3378
  NumberTypeAnnotation(
@@ -3546,15 +3549,15 @@ const getTransforms = (
3546
3549
  ```
3547
3550
  type T = { ...T1, b: string };
3548
3551
  // becomes
3549
- type T = Omit<T1, keyof { b: string }> & { b: string };
3552
+ type T = Omit<T1, 'b'> & { b: string };
3550
3553
  ```
3551
3554
  ```
3552
3555
  type T = { ...T1, ...T2, ...T3, b: string };
3553
3556
  // becomes
3554
3557
  type T =
3555
- & Omit<T1, keyof T2 | keyof T3 | keyof { b: string }>
3556
- & Omit<T2, keyof T3 | keyof { b: string }>
3557
- & Omit<T3, keyof { b: string }>
3558
+ & Omit<T1, keyof T2 | keyof T3 | 'b'>
3559
+ & Omit<T2, keyof T3 | 'b'>
3560
+ & Omit<T3, 'b'>
3558
3561
  & { b: string };
3559
3562
  ```
3560
3563
 
@@ -3616,10 +3619,33 @@ const getTransforms = (
3616
3619
  members: tsBody,
3617
3620
  };
3618
3621
 
3622
+ // When the non-spread properties have statically known key
3623
+ // names, emit them as string literal types directly instead of
3624
+ // wrapping in `keyof`. Falls back to `keyof objectType` when
3625
+ // any key is computed or otherwise non-extractable.
3626
+ const objectKeyTypes: ReadonlyArray<TSESTree.TypeNode> =
3627
+ extractPropertyKeyLiterals(tsBody) ?? [
3628
+ {
3629
+ type: 'TSTypeOperator',
3630
+ loc: DUMMY_LOC,
3631
+ operator: 'keyof',
3632
+ typeAnnotation: objectType,
3633
+ },
3634
+ ];
3635
+
3619
3636
  const intersectionMembers: Array<TSESTree.TypeNode> = [];
3620
3637
  for (let i = 0; i < typesToIntersect.length; i += 1) {
3621
3638
  const currentType = typesToIntersect[i];
3622
3639
  const remainingTypes = typesToIntersect.slice(i + 1);
3640
+ const omitKeyTypes: Array<TSESTree.TypeNode> = [
3641
+ ...remainingTypes.map(t => ({
3642
+ type: 'TSTypeOperator',
3643
+ loc: DUMMY_LOC,
3644
+ operator: 'keyof',
3645
+ typeAnnotation: t,
3646
+ })),
3647
+ ...objectKeyTypes,
3648
+ ];
3623
3649
  intersectionMembers.push({
3624
3650
  type: 'TSTypeReference',
3625
3651
  loc: DUMMY_LOC,
@@ -3628,29 +3654,18 @@ const getTransforms = (
3628
3654
  loc: DUMMY_LOC,
3629
3655
  name: 'Omit',
3630
3656
  },
3631
- typeParameters: {
3657
+ typeArguments: {
3632
3658
  type: 'TSTypeParameterInstantiation',
3633
3659
  loc: DUMMY_LOC,
3634
3660
  params: [
3635
3661
  currentType,
3636
- {
3637
- type: 'TSUnionType',
3638
- loc: DUMMY_LOC,
3639
- types: [
3640
- ...remainingTypes.map(t => ({
3641
- type: 'TSTypeOperator',
3662
+ omitKeyTypes.length === 1
3663
+ ? omitKeyTypes[0]
3664
+ : {
3665
+ type: 'TSUnionType',
3642
3666
  loc: DUMMY_LOC,
3643
- operator: 'keyof',
3644
- typeAnnotation: t,
3645
- })),
3646
- {
3647
- type: 'TSTypeOperator',
3648
- loc: DUMMY_LOC,
3649
- operator: 'keyof',
3650
- typeAnnotation: objectType,
3667
+ types: omitKeyTypes,
3651
3668
  },
3652
- ],
3653
- },
3654
3669
  ],
3655
3670
  },
3656
3671
  });
@@ -3866,7 +3881,7 @@ const getTransforms = (
3866
3881
  loc: DUMMY_LOC,
3867
3882
  name: 'NonNullable',
3868
3883
  },
3869
- typeParameters: {
3884
+ typeArguments: {
3870
3885
  type: 'TSTypeParameterInstantiation',
3871
3886
  loc: DUMMY_LOC,
3872
3887
  params: [transformTypeAnnotationType(node.objectType)],
@@ -3931,12 +3946,12 @@ const getTransforms = (
3931
3946
  return {
3932
3947
  type: 'TSLiteralType',
3933
3948
  loc: DUMMY_LOC,
3934
- literal: ({
3949
+ literal: {
3935
3950
  type: 'Literal',
3936
3951
  loc: DUMMY_LOC,
3937
3952
  value: node.value,
3938
3953
  raw: node.raw,
3939
- }: TSESTree.StringLiteral),
3954
+ } as TSESTree.StringLiteral,
3940
3955
  };
3941
3956
  },
3942
3957
  StringTypeAnnotation(
@@ -4064,14 +4079,14 @@ const getTransforms = (
4064
4079
  type: 'TSTypeQuery',
4065
4080
  loc: DUMMY_LOC,
4066
4081
  exprName: transform.Identifier(node.argument),
4067
- typeParameters: undefined,
4082
+ typeArguments: undefined,
4068
4083
  };
4069
4084
  case 'QualifiedTypeofIdentifier':
4070
4085
  return {
4071
4086
  type: 'TSTypeQuery',
4072
4087
  loc: DUMMY_LOC,
4073
4088
  exprName: transform.QualifiedTypeofIdentifier(node.argument),
4074
- typeParameters: undefined,
4089
+ typeArguments: undefined,
4075
4090
  };
4076
4091
  }
4077
4092
  },
@@ -4249,7 +4264,7 @@ const getTransforms = (
4249
4264
  name: `ReactNode`,
4250
4265
  },
4251
4266
  },
4252
- typeParameters: undefined,
4267
+ typeArguments: undefined,
4253
4268
  };
4254
4269
  }
4255
4270
  }
@@ -4283,7 +4298,7 @@ const getTransforms = (
4283
4298
  name: `ReactNode`,
4284
4299
  },
4285
4300
  },
4286
- typeParameters: undefined,
4301
+ typeArguments: undefined,
4287
4302
  },
4288
4303
  };
4289
4304
 
@@ -1,12 +1,3 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
1
  'use strict';
11
2
 
12
3
  Object.defineProperty(exports, "__esModule", {
@@ -19,7 +19,7 @@ export type SourceMapperParams = {
19
19
  module: string,
20
20
  };
21
21
 
22
- export type MapperOptions = $ReadOnly<{
22
+ export type MapperOptions = Readonly<{
23
23
  sourceMapper: SourceMapperParams => string,
24
24
  }>;
25
25