Skip to content

Commit

Permalink
Support as cast expressions in super class types
Browse files Browse the repository at this point in the history
Summary:
Changelog [flow-api-translator]: Added support for `class A extends (Foo as Bar)` in the flow-api-translator

D58577282 added support for the legacy `TypeCastExpression`s, but did not add support for `AsExpression`s. Add support here.

Reviewed By: SamChou19815

Differential Revision: D59928177

fbshipit-source-id: 4a1d745428fc016da9dd7004aa8e26d223d09deb
  • Loading branch information
gkz authored and facebook-github-bot committed Jul 18, 2024
1 parent fca2369 commit 175d85f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,12 @@ describe('flowToFlowDef', () => {
`declare export class Foo<T> extends X {}`,
);
});
it('extends as cast expression', async () => {
await expectTranslate(
`export class Foo<T> extends (Bar as X) {}`,
`declare export class Foo<T> extends X {}`,
);
});
it('extends type cast typeof expression', async () => {
await expectTranslate(
`export class Foo<T> extends (Bar: typeof X) {}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,12 @@ function convertSuperClass(
context,
);
}
case 'TypeCastExpression': {
const typeAnnotation = superClass.typeAnnotation.typeAnnotation;
case 'TypeCastExpression':
case 'AsExpression': {
const typeAnnotation =
superClass.type === 'TypeCastExpression'
? superClass.typeAnnotation.typeAnnotation
: superClass.typeAnnotation;

if (typeAnnotation.type === 'GenericTypeAnnotation') {
return convertSuperClassHelper(
Expand Down

0 comments on commit 175d85f

Please sign in to comment.