Skip to content

Commit 8656e4e

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Translate $ArrayLike to ArrayLike
Summary: Updates `flow-api-translator` in a way that it translates Flow's `$ArrayLike` to TS's `ArrayLike`. Reviewed By: pieterv Differential Revision: D70387099 fbshipit-source-id: 31a5f2ba08e576b71fa15824716561641f85a562
1 parent bc17d96 commit 8656e4e

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
type T = $ArrayLike<Foo>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`flowDefToTSDef types/utilities/$ArrayLike 1`] = `
4+
"/**
5+
* Copyright (c) Meta Platforms, Inc. and affiliates.
6+
*
7+
* This source code is licensed under the MIT license found in the
8+
* LICENSE file in the root directory of this source tree.
9+
*
10+
*
11+
* @format
12+
*/
13+
14+
type T = ArrayLike<Foo>;
15+
"
16+
`;

tools/hermes-parser/js/flow-api-translator/src/flowDefToTSDef.js

+18
Original file line numberDiff line numberDiff line change
@@ -2069,6 +2069,24 @@ const getTransforms = (
20692069
return unsupportedAnnotation(node, fullTypeName);
20702070
}
20712071

2072+
case '$ArrayLike': {
2073+
// `$ArrayLike<T>` => `ArrayLike<T>`
2074+
return {
2075+
type: 'TSTypeReference',
2076+
loc: DUMMY_LOC,
2077+
typeName: {
2078+
type: 'Identifier',
2079+
loc: DUMMY_LOC,
2080+
name: 'ArrayLike',
2081+
},
2082+
typeParameters: {
2083+
type: 'TSTypeParameterInstantiation',
2084+
loc: DUMMY_LOC,
2085+
params: assertHasExactlyNTypeParameters(1),
2086+
},
2087+
};
2088+
}
2089+
20722090
case '$Diff':
20732091
case '$Rest': {
20742092
// `$Diff<A, B>` => `Pick<A, Exclude<keyof A, keyof B>>`

0 commit comments

Comments
 (0)